1
0
mirror of https://gitlab.com/animath/si/plateforme-corres2math.git synced 2024-12-05 02:06:52 +00:00

Create more mailing lists

This commit is contained in:
Yohann D'ANELLO 2020-11-14 22:18:35 +01:00
parent 02ca1d1efe
commit 10932d1cc5
3 changed files with 55 additions and 0 deletions

View File

@ -0,0 +1,39 @@
from django.db.models import Q
from corres2math.lists import get_sympa_client
from django.core.management import BaseCommand
from participation.models import Team
from registration.models import CoachRegistration, StudentRegistration
class Command(BaseCommand):
def handle(self, *args, **options):
"""
Create Sympa mailing lists and register teams.
"""
sympa = get_sympa_client()
sympa.create_list("equipes", "Équipes des Correspondances", "hotline",
"Liste de diffusion pour contacter toutes les équipes validées des Correspondances.",
"education", raise_error=False)
sympa.create_list("equipes-non-valides", "Équipes des Correspondances", "hotline",
"Liste de diffusion pour contacter toutes les équipes non-validées des Correspondances.",
"education", raise_error=False)
for problem in range(1, 4):
sympa.create_list(f"probleme-{problem}",
f"Équipes des Correspondances participant au problème {problem}", "hotline",
f"Liste de diffusion pour contacter les équipes participant au problème {problem}"
f" des Correspondances.", "education", raise_error=False)
for team in Team.objects.filter(participation__valid=True).all():
sympa.subscribe(team.email, "equipes", f"Equipe {team.name}", True, True)
sympa.subscribe(team.email, f"probleme-{team.participation.problem}", f"Equipe {team.name}", True)
for team in Team.objects.filter(Q(participation__valid=False) | Q(participation__valid__isnull=True)).all():
sympa.subscribe(team.email, "equipes-non-valides", f"Equipe {team.name}", True)
for student in StudentRegistration.objects.filter(team__isnull=False).all():
sympa.subscribe(student.user.email, f"equipe-{student.team.trigram.lower}", True, f"{student}")
for coach in CoachRegistration.objects.filter(team__isnull=False).all():
sympa.subscribe(coach.user.email, f"equipe-{coach.team.trigram.lower}", True, f"{coach}")

View File

@ -65,11 +65,22 @@ class Team(models.Model):
"education",
raise_error=False,
)
if self.participation.valid:
get_sympa_client().subscribe(self.email, "equipes", False, f"Equipe {self.name}")
get_sympa_client().subscribe(self.email, f"probleme-{self.participation.problem}", False,
f"Equipe {self.name}")
else:
get_sympa_client().subscribe(self.email, "equipes-non-valides", False)
def delete_mailing_list(self):
"""
Drop the Sympa mailing list, if the team is empty or if the trigram changed.
"""
if self.participation.valid:
get_sympa_client().unsubscribe(self.email, "equipes", False)
get_sympa_client().unsubscribe(self.email, f"probleme-{self.participation.problem}", False)
else:
get_sympa_client().unsubscribe(self.email, "equipes-non-valides", False)
get_sympa_client().delete_list(f"equipe-{self.trigram}")
def save(self, *args, **kwargs):

View File

@ -223,6 +223,11 @@ class TeamDetailView(LoginRequiredMixin, FormMixin, ProcessFormView, DetailView)
mail_plain = render_to_string("participation/mails/team_validated.txt", mail_context)
mail_html = render_to_string("participation/mails/team_validated.html", mail_context)
send_mail("[Corres2math] Équipe validée", mail_plain, None, [self.object.email], html_message=mail_html)
get_sympa_client().subscribe(self.object.email, "equipes", False, f"Equipe {self.object.name}")
get_sympa_client().unsubscribe(self.object.email, "equipes-non-valides", False)
get_sympa_client().subscribe(self.object.email, f"probleme-{self.object.participation.problem}", False,
f"Equipe {self.object.name}")
elif "invalidate" in self.request.POST:
self.object.participation.valid = None
self.object.participation.save()