1
0
mirror of https://gitlab.com/animath/si/plateforme.git synced 2024-11-30 05:33:01 +00:00
plateforme-tfjm2/participation/signals.py
Emmy D'Anello 93a2e2436d
Drop Matrix support
Signed-off-by: Emmy D'Anello <emmy.danello@animath.fr>
2024-01-13 16:49:49 +01:00

48 lines
1.8 KiB
Python

# Copyright (C) 2020 by Animath
# SPDX-License-Identifier: GPL-3.0-or-later
from typing import Union
from participation.models import Note, Participation, Passage, Pool, Team
from tfjm.lists import get_sympa_client
def create_team_participation(instance, created, raw, **_):
"""
When a team got created, create an associated participation.
"""
if not raw:
participation = Participation.objects.get_or_create(team=instance)[0]
participation.save()
if not created:
participation.team.create_mailing_list()
def update_mailing_list(instance: Team, raw, **_):
"""
When a team name or trigram got updated, update mailing lists
"""
if instance.pk and not raw:
old_team = Team.objects.get(pk=instance.pk)
if old_team.trigram != instance.trigram:
# Delete old mailing list, create a new one
old_team.delete_mailing_list()
instance.create_mailing_list()
# Subscribe all team members in the 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.coaches.all():
get_sympa_client().subscribe(coach.user.email, f"equipe-{instance.trigram.lower()}", False,
f"{coach.user.first_name} {coach.user.last_name}")
def create_notes(instance: Union[Passage, Pool], raw, **_):
if not raw:
if isinstance(instance, Pool):
for passage in instance.passages.all():
create_notes(passage, raw)
return
for jury in instance.pool.juries.all():
Note.objects.get_or_create(jury=jury, passage=instance)