From 34924db36040ab00ceb0bde3a04458c4d6e28d9b Mon Sep 17 00:00:00 2001 From: Razmig Sarkissian Date: Mon, 20 Oct 2025 14:05:29 +0200 Subject: [PATCH] Add user-initiated registration cancellation logic --- tournaments/models/team_registration.py | 8 ++++++++ tournaments/services/tournament_unregistration.py | 3 ++- tournaments/signals.py | 6 +++++- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/tournaments/models/team_registration.py b/tournaments/models/team_registration.py index 09c3e66..514730f 100644 --- a/tournaments/models/team_registration.py +++ b/tournaments/models/team_registration.py @@ -37,6 +37,7 @@ class TeamRegistration(TournamentSubModel): final_ranking = models.IntegerField(null=True, blank=True) points_earned = models.IntegerField(null=True, blank=True) unique_random_index = models.IntegerField(default=0) + user_canceled_registration = False def delete_dependencies(self): for player_registration in self.player_registrations.all(): @@ -560,3 +561,10 @@ class TeamRegistration(TournamentSubModel): return player_registrations[0].player_contact() return None + + def cancel_registration(self): + self.walk_out = True + self.user_canceled_registration = True + + def user_did_cancel_registration(self): + return self.user_canceled_registration and self.walk_out diff --git a/tournaments/services/tournament_unregistration.py b/tournaments/services/tournament_unregistration.py index 557649d..ffe6ba1 100644 --- a/tournaments/services/tournament_unregistration.py +++ b/tournaments/services/tournament_unregistration.py @@ -110,7 +110,8 @@ class TournamentUnregistrationService: def _delete_registered_team(self): team_registration = self.player_registration.team_registration - team_registration.delete() + team_registration.cancel_registration() + team_registration.save() def _cleanup_session(self): self.request.session['team_registration'] = [] diff --git a/tournaments/signals.py b/tournaments/signals.py index 8ee9314..5671ceb 100644 --- a/tournaments/signals.py +++ b/tournaments/signals.py @@ -190,7 +190,11 @@ def warn_team_walkout_status_change(sender, instance, **kwargs): notify_team(instance, instance.tournament, TeamEmailType.OUT_OF_WALKOUT_IS_IN) elif not previous_instance.out_of_tournament() and instance.out_of_tournament(): instance.cancel_time_to_confirm() - notify_team(instance, instance.tournament, TeamEmailType.WALKOUT) + print("User did cancel registration", instance.user_did_cancel_registration()) + if instance.user_did_cancel_registration(): + notify_team(instance, instance.tournament, TeamEmailType.UNREGISTERED) + else: + notify_team(instance, instance.tournament, TeamEmailType.WALKOUT) if was_out and not is_out: first_out_of_list = instance.tournament.first_waiting_list_team(current_teams)