mirror of
https://gitlab.com/animath/si/plateforme.git
synced 2024-12-25 07:02:22 +00:00
Don't trigger signals on raw imports
Signed-off-by: Emmy D'Anello <emmy.danello@animath.fr>
This commit is contained in:
parent
7364d27b4b
commit
30efff0d9d
@ -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
|
||||||
|
@ -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.
|
||||||
"""
|
"""
|
||||||
|
if not raw:
|
||||||
participation = Participation.objects.get_or_create(team=instance)[0]
|
participation = Participation.objects.get_or_create(team=instance)[0]
|
||||||
participation.save()
|
participation.save()
|
||||||
if not created:
|
if not created:
|
||||||
participation.team.create_mailing_list()
|
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,7 +37,8 @@ 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 not raw:
|
||||||
if isinstance(instance, Pool):
|
if isinstance(instance, Pool):
|
||||||
for passage in instance.passages.all():
|
for passage in instance.passages.all():
|
||||||
create_notes(passage)
|
create_notes(passage)
|
||||||
|
@ -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
|
||||||
|
Loading…
Reference in New Issue
Block a user