2020-10-11 15:10:59 +00:00
|
|
|
from corres2math.lists import get_sympa_client
|
|
|
|
from participation.models import Participation, Team, Video
|
2020-09-24 08:21:50 +00:00
|
|
|
|
|
|
|
|
|
|
|
def create_team_participation(instance, **_):
|
2020-09-27 12:32:05 +00:00
|
|
|
participation = Participation.objects.get_or_create(team=instance)[0]
|
|
|
|
if not participation.solution:
|
|
|
|
participation.solution = Video.objects.create()
|
|
|
|
if not participation.synthesis:
|
|
|
|
participation.synthesis = Video.objects.create()
|
|
|
|
participation.save()
|
2020-10-11 15:10:59 +00:00
|
|
|
|
|
|
|
|
|
|
|
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}")
|
2020-10-15 15:20:58 +00:00
|
|
|
|
|
|
|
|
|
|
|
def delete_related_videos(instance: Participation, **_):
|
|
|
|
if instance.solution:
|
|
|
|
instance.solution.delete()
|
|
|
|
if instance.synthesis:
|
|
|
|
instance.synthesis.delete()
|