mirror of
https://gitlab.com/animath/si/plateforme-corres2math.git
synced 2024-12-05 01:26:54 +00:00
Update the mailing list if the team name or trigram got updated
This commit is contained in:
parent
a5e7325a5b
commit
b3db01c02e
@ -1,10 +1,11 @@
|
||||
from django.apps import AppConfig
|
||||
from django.db.models.signals import post_save
|
||||
from django.db.models.signals import post_save, pre_save
|
||||
|
||||
|
||||
class ParticipationConfig(AppConfig):
|
||||
name = 'participation'
|
||||
|
||||
def ready(self):
|
||||
from participation.signals import create_team_participation
|
||||
from participation.signals import create_team_participation, update_mailing_list
|
||||
pre_save.connect(update_mailing_list, "participation.Team")
|
||||
post_save.connect(create_team_participation, "participation.Team")
|
||||
|
@ -53,6 +53,7 @@ class Team(models.Model):
|
||||
if not self.access_code:
|
||||
self.access_code = get_random_string(6)
|
||||
self.create_mailing_list()
|
||||
|
||||
return super().save(*args, **kwargs)
|
||||
|
||||
def __str__(self):
|
||||
|
@ -1,4 +1,5 @@
|
||||
from participation.models import Participation, Video
|
||||
from corres2math.lists import get_sympa_client
|
||||
from participation.models import Participation, Team, Video
|
||||
|
||||
|
||||
def create_team_participation(instance, **_):
|
||||
@ -8,3 +9,17 @@ def create_team_participation(instance, **_):
|
||||
if not participation.synthesis:
|
||||
participation.synthesis = Video.objects.create()
|
||||
participation.save()
|
||||
|
||||
|
||||
def update_mailing_list(instance: Team, **_):
|
||||
if instance.pk:
|
||||
old_team = Team.objects.get(pk=instance.pk)
|
||||
if old_team.name != instance.name or old_team.trigram != instance.trigram:
|
||||
old_team.delete_mailing_list()
|
||||
instance.create_mailing_list()
|
||||
for student in instance.students.all():
|
||||
get_sympa_client().subscribe(student.user.email, f"equipe-{instance.trigram.lower()}", False,
|
||||
f"{student.user.first_name} {student.user.last_name}")
|
||||
for coach in instance.coachs.all():
|
||||
get_sympa_client().subscribe(coach.user.email, f"equipe-{instance.trigram.lower()}", False,
|
||||
f"{coach.user.first_name} {coach.user.last_name}")
|
||||
|
@ -18,9 +18,9 @@ def send_email_link(instance, **_):
|
||||
registration.user = instance
|
||||
registration.send_email_validation_link()
|
||||
|
||||
if registration.team:
|
||||
get_sympa_client().unsubscribe(old_instance.email, f"equipe-{registration.team.trigram}", False)
|
||||
get_sympa_client().subscribe(instance.email, f"equipe-{registration.team.trigram}", False,
|
||||
if registration.participates and registration.team:
|
||||
get_sympa_client().unsubscribe(old_instance.email, f"equipe-{registration.team.trigram.lower()}", False)
|
||||
get_sympa_client().subscribe(instance.email, f"equipe-{registration.team.trigram.lower()}", False,
|
||||
f"{instance.first_name} {instance.last_name}")
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user