mirror of
				https://gitlab.com/animath/si/plateforme.git
				synced 2025-11-01 00:24:29 +01:00 
			
		
		
		
	Don't trigger signals on raw imports
Signed-off-by: Emmy D'Anello <emmy.danello@animath.fr>
This commit is contained in:
		| @@ -34,13 +34,13 @@ def pre_save_object(sender, instance, **kwargs): | ||||
|         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 | ||||
|     in order to store each modification made | ||||
|     """ | ||||
|     # 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 | ||||
|  | ||||
|     # noinspection PyProtectedMember | ||||
|   | ||||
| @@ -6,21 +6,22 @@ from participation.models import Note, Participation, Passage, Pool, Team | ||||
| 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. | ||||
|     """ | ||||
|     participation = Participation.objects.get_or_create(team=instance)[0] | ||||
|     participation.save() | ||||
|     if not created: | ||||
|         participation.team.create_mailing_list() | ||||
|     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, **_): | ||||
| def update_mailing_list(instance: Team, raw, **_): | ||||
|     """ | ||||
|     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) | ||||
|         if old_team.trigram != instance.trigram: | ||||
|             # TODO Rename Matrix room | ||||
| @@ -36,11 +37,12 @@ def update_mailing_list(instance: Team, **_): | ||||
|                                              f"{coach.user.first_name} {coach.user.last_name}") | ||||
|  | ||||
|  | ||||
| def create_notes(instance: Union[Passage, Pool], **_): | ||||
|     if isinstance(instance, Pool): | ||||
|         for passage in instance.passages.all(): | ||||
|             create_notes(passage) | ||||
|         return | ||||
| def create_notes(instance: Union[Passage, Pool], raw, **_): | ||||
|     if not raw: | ||||
|         if isinstance(instance, Pool): | ||||
|             for passage in instance.passages.all(): | ||||
|                 create_notes(passage) | ||||
|             return | ||||
|  | ||||
|     for jury in instance.pool.juries.all(): | ||||
|         Note.objects.get_or_create(jury=jury, passage=instance) | ||||
|         for jury in instance.pool.juries.all(): | ||||
|             Note.objects.get_or_create(jury=jury, passage=instance) | ||||
|   | ||||
| @@ -43,12 +43,12 @@ def create_admin_registration(instance, **_): | ||||
|         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. | ||||
|     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] | ||||
|         if instance.team and instance.team.participation.valid and instance.team.participation.tournament.price == 0: | ||||
|             payment.valid = True | ||||
|   | ||||
		Reference in New Issue
	
	Block a user