1
0
mirror of https://gitlab.com/animath/si/plateforme.git synced 2024-12-24 17:42:23 +00:00

Don't trigger signals on raw imports

Signed-off-by: Emmy D'Anello <emmy.danello@animath.fr>
This commit is contained in:
Emmy D'Anello 2023-03-22 14:42:14 +01:00
parent 7364d27b4b
commit 30efff0d9d
Signed by: ynerant
GPG Key ID: 3A75C55819C8CF85
3 changed files with 20 additions and 18 deletions

View File

@ -34,13 +34,13 @@ def pre_save_object(sender, instance, **kwargs):
instance._previous = None instance._previous = None
def save_object(sender, instance, **kwargs): def save_object(sender, instance, raw, **kwargs):
""" """
Each time a model is saved, an entry in the table `Changelog` is added in the database Each time a model is saved, an entry in the table `Changelog` is added in the database
in order to store each modification made in order to store each modification made
""" """
# noinspection PyProtectedMember # noinspection PyProtectedMember
if instance._meta.label_lower in EXCLUDED or hasattr(instance, "_no_signal"): if instance._meta.label_lower in EXCLUDED or hasattr(instance, "_no_signal") or raw:
return return
# noinspection PyProtectedMember # noinspection PyProtectedMember

View File

@ -6,21 +6,22 @@ from participation.models import Note, Participation, Passage, Pool, Team
from tfjm.lists import get_sympa_client from tfjm.lists import get_sympa_client
def create_team_participation(instance, created, **_): def create_team_participation(instance, created, raw, **_):
""" """
When a team got created, create an associated participation. When a team got created, create an associated participation.
""" """
participation = Participation.objects.get_or_create(team=instance)[0] if not raw:
participation.save() participation = Participation.objects.get_or_create(team=instance)[0]
if not created: participation.save()
participation.team.create_mailing_list() if not created:
participation.team.create_mailing_list()
def update_mailing_list(instance: Team, **_): def update_mailing_list(instance: Team, raw, **_):
""" """
When a team name or trigram got updated, update mailing lists and Matrix rooms When a team name or trigram got updated, update mailing lists and Matrix rooms
""" """
if instance.pk: if instance.pk and not raw:
old_team = Team.objects.get(pk=instance.pk) old_team = Team.objects.get(pk=instance.pk)
if old_team.trigram != instance.trigram: if old_team.trigram != instance.trigram:
# TODO Rename Matrix room # TODO Rename Matrix room
@ -36,11 +37,12 @@ def update_mailing_list(instance: Team, **_):
f"{coach.user.first_name} {coach.user.last_name}") f"{coach.user.first_name} {coach.user.last_name}")
def create_notes(instance: Union[Passage, Pool], **_): def create_notes(instance: Union[Passage, Pool], raw, **_):
if isinstance(instance, Pool): if not raw:
for passage in instance.passages.all(): if isinstance(instance, Pool):
create_notes(passage) for passage in instance.passages.all():
return create_notes(passage)
return
for jury in instance.pool.juries.all(): for jury in instance.pool.juries.all():
Note.objects.get_or_create(jury=jury, passage=instance) Note.objects.get_or_create(jury=jury, passage=instance)

View File

@ -43,12 +43,12 @@ def create_admin_registration(instance, **_):
VolunteerRegistration.objects.get_or_create(user=instance, admin=True) VolunteerRegistration.objects.get_or_create(user=instance, admin=True)
def create_payment(instance: Registration, **_): def create_payment(instance: Registration, raw, **_):
""" """
When a user is saved, create the associated payment. When a user is saved, create the associated payment.
For a free tournament, the payment is valid. For a free tournament, the payment is valid.
""" """
if instance.participates: if instance.participates and not raw:
payment = Payment.objects.get_or_create(registration=instance)[0] payment = Payment.objects.get_or_create(registration=instance)[0]
if instance.team and instance.team.participation.valid and instance.team.participation.tournament.price == 0: if instance.team and instance.team.participation.valid and instance.team.participation.tournament.price == 0:
payment.valid = True payment.valid = True