From 715972b11584d56d493e1555fd11c7b777c097a6 Mon Sep 17 00:00:00 2001 From: Raz Date: Tue, 15 Apr 2025 12:01:12 +0200 Subject: [PATCH] fix ttc bugs --- tournaments/apps.py | 2 +- tournaments/models/tournament.py | 3 - tournaments/services/email_service.py | 18 ++- tournaments/signals.py | 6 +- tournaments/static/tournaments/css/style.css | 2 +- tournaments/tasks.py | 3 +- .../tournaments/tournament_info.html | 131 +++++++++--------- tournaments/views.py | 6 +- 8 files changed, 88 insertions(+), 83 deletions(-) diff --git a/tournaments/apps.py b/tournaments/apps.py index c904e83..bcbf8fe 100644 --- a/tournaments/apps.py +++ b/tournaments/apps.py @@ -18,7 +18,7 @@ class TournamentsConfig(AppConfig): Task.objects.filter(task_name='tournaments.tasks.check_confirmation_deadlines').delete() # Schedule the task to run every 30 minutes (1800 seconds) - check_confirmation_deadlines(repeat=1800) + check_confirmation_deadlines(repeat=settings.BACKGROUND_TASK_REPEAT_INTERVAL * 60) except: # Handle exceptions during startup pass diff --git a/tournaments/models/tournament.py b/tournaments/models/tournament.py index 050e80a..d0b4265 100644 --- a/tournaments/models/tournament.py +++ b/tournaments/models/tournament.py @@ -1488,9 +1488,6 @@ class Tournament(BaseModel): if self.enable_time_to_confirm is False: return None - if waiting_list_count == 0: - return None - config = settings.TOURNAMENT_SETTINGS['TIME_TO_CONFIRM'] TIME_PROXIMITY_RULES = config['TIME_PROXIMITY_RULES'] WAITING_LIST_RULES = config['WAITING_LIST_RULES'] diff --git a/tournaments/services/email_service.py b/tournaments/services/email_service.py index 1c736c5..508fa9f 100644 --- a/tournaments/services/email_service.py +++ b/tournaments/services/email_service.py @@ -17,7 +17,17 @@ class TeamEmailType(Enum): WALKOUT = "walkout" UNEXPECTED_OUT_OF_TOURNAMENT = 'unexpected_out_of_tournament' - def email_subject(self) -> str: + def email_subject(self, time_to_confirm=None) -> str: + confirmation_types = [ + self.REGISTERED, + self.OUT_OF_WAITING_LIST, + self.IN_TOURNAMENT_STRUCTURE, + self.OUT_OF_WALKOUT_IS_IN + ] + + if time_to_confirm and self in confirmation_types: + return "Participation en attente de confirmation" + else: subjects = { self.REGISTERED: "Participation confirmée", self.WAITING_LIST: "Liste d'attente", @@ -213,7 +223,7 @@ class TournamentEmailService: def _build_out_of_tournament_email_body(tournament, captain, tournament_details_str, other_player): body_parts = [ "Bonjour,\n\n", - f"Suite à une modification de la taille du tournoi, vous ne faites plus partie des équipes participant au tournoi {tournament_details_str}, prévu le {tournament.formatted_start_date()} au club {tournament.event.club.name}" + f"Suite à une modification de la taille du tournoi, vous avez été placé en liste d'attente. Votre participation au tournoi {tournament_details_str}, prévu le {tournament.formatted_start_date()} au club {tournament.event.club.name} n'est plus confirmée." ] absolute_url = f"https://padelclub.app/tournament/{tournament.id}/info" @@ -295,7 +305,7 @@ class TournamentEmailService: def _build_unexpected_out_of_tournament_email_body(tournament, captain, tournament_details_str, other_player): body_parts = [ "Bonjour,\n\n", - f"En raison d'une décision du juge-arbitre, vous ne faites plus partie des équipes participant au tournoi {tournament_details_str}, prévu le {tournament.formatted_start_date()} au club {tournament.event.club.name}" + f"En raison d'une décision du juge-arbitre, vous avez été placé en liste d'attente. Votre participation au tournoi {tournament_details_str}, prévu le {tournament.formatted_start_date()} au club {tournament.event.club.name} n'est plus confirmée." ] absolute_url = f"https://padelclub.app/tournament/{tournament.id}/info" @@ -415,7 +425,7 @@ class TournamentEmailService: if email_body is None: return - topic = message_type.email_subject() + topic = message_type.email_subject(captain.time_to_confirm) email_subject = TournamentEmailService.email_subject(tournament, topic) TournamentEmailService._send_email(captain.email, email_subject, email_body) diff --git a/tournaments/signals.py b/tournaments/signals.py index 8144283..838c290 100644 --- a/tournaments/signals.py +++ b/tournaments/signals.py @@ -131,6 +131,7 @@ def check_waiting_list(sender, instance, **kwargs): notify_team(team.team_registration, instance, TeamEmailType.IN_TOURNAMENT_STRUCTURE) for team in teams_out_to_warn: + team.team_registration.set_time_to_confirm(None) notify_team(team.team_registration, instance, TeamEmailType.OUT_OF_TOURNAMENT_STRUCTURE) @receiver(pre_save, sender=TeamRegistration) @@ -160,7 +161,7 @@ def warn_team_walkout_status_change(sender, instance, **kwargs): if not instance.out_of_tournament() and is_out and (previous_instance.out_of_tournament() or not was_out): notify_team(instance, instance.tournament, TeamEmailType.OUT_OF_WALKOUT_WAITING_LIST) elif was_out and not is_out: - waiting_list_teams = instance.tournament.waiting_list_teams(previous_teams) + waiting_list_teams = instance.tournament.waiting_list_teams(current_teams) if waiting_list_teams is not None: ttc = instance.tournament.calculate_time_to_confirm(len(waiting_list_teams)) instance.set_time_to_confirm(ttc) @@ -171,11 +172,12 @@ def warn_team_walkout_status_change(sender, instance, **kwargs): if was_out and not is_out: first_out_of_list = instance.tournament.first_waiting_list_team(current_teams) if first_out_of_list: + first_out_of_list.set_time_to_confirm(None) notify_team(first_out_of_list, instance.tournament, TeamEmailType.UNEXPECTED_OUT_OF_TOURNAMENT) elif not was_out and is_out: first_waiting_list_team = instance.tournament.first_waiting_list_team(previous_teams) if first_waiting_list_team: - waiting_list_teams = instance.tournament.waiting_list_teams(previous_teams) + waiting_list_teams = instance.tournament.waiting_list_teams(current_teams) if waiting_list_teams is not None: ttc = instance.tournament.calculate_time_to_confirm(len(waiting_list_teams)) first_waiting_list_team.set_time_to_confirm(ttc) diff --git a/tournaments/static/tournaments/css/style.css b/tournaments/static/tournaments/css/style.css index f54f749..a652b1b 100644 --- a/tournaments/static/tournaments/css/style.css +++ b/tournaments/static/tournaments/css/style.css @@ -162,7 +162,7 @@ tr { .rounded-button { background-color: #fae7ce; /* Green background */ color: #505050; /* White text */ - padding: 15px 32px; /* Some padding */ + padding: 12px 24px; /* Some padding */ font-size: 1em; font-weight: 800; cursor: pointer; /* Add a mouse pointer on hover */ diff --git a/tournaments/tasks.py b/tournaments/tasks.py index 443700d..da80931 100644 --- a/tournaments/tasks.py +++ b/tournaments/tasks.py @@ -1,12 +1,13 @@ from background_task import background from django.utils import timezone from django.db import transaction +from django.conf import settings from .models import PlayerRegistration from .models.enums import RegistrationStatus from .services.email_service import TournamentEmailService, TeamEmailType -@background(schedule=1) # Run every 30 minutes (30*60 seconds) +@background(schedule=settings.BACKGROUND_SCHEDULED_TASK_INTERVAL * 60) # Run every 30 minutes (30*60 seconds) def check_confirmation_deadlines(): """ Periodic task to check for expired confirmation deadlines diff --git a/tournaments/templates/tournaments/tournament_info.html b/tournaments/templates/tournaments/tournament_info.html index 4df2031..b686adb 100644 --- a/tournaments/templates/tournaments/tournament_info.html +++ b/tournaments/templates/tournaments/tournament_info.html @@ -14,38 +14,10 @@
-
+
{% if tournament.enable_online_registration and team %}

Votre équipe

- {% if team.needs_confirmation %} -
-

Confirmation requise

-

Votre place dans le tournoi a été libérée suite à une désinscription.

- {% if tournament.should_request_payment and tournament.online_payment_is_mandatory %} -

Vous devez payer votre participation pour confirmer votre inscription.

- {% endif %} - {% if team.get_confirmation_deadline %} - {% timezone tournament.timezone %} - {% with time_to_confirm=team.get_confirmation_deadline %} - {% now "Y-m-d H:i:s" as current_time_str %} - {% if time_to_confirm %} - {% if time_to_confirm|date:"Y-m-d H:i:s" > current_time_str %} -

Vous devez confirmer votre participation avant le:

-

{{ time_to_confirm|date:"d/m/Y à H:i" }}

- -

Temps restant: {{ time_to_confirm|timeuntil }}

- {% else %} -

- Le délai de confirmation est expiré. Votre place a été proposée à une autre équipe. -

- {% endif %} - {% endif %} - {% endwith %} - {% endtimezone %} - {% endif %} -
- {% endif %} {% if messages %}
{% for message in messages %} @@ -55,7 +27,6 @@ {% endfor %}
{% endif %} -
{% if team.is_in_waiting_list >= 0 %} Tournoi complet, vous êtes en liste d'attente. @@ -81,6 +52,33 @@
Inscrits le {{ team.local_registration_date }}

+ {% if team.needs_confirmation %} +

Confirmation requise

+
Une place dans le tournoi a été libérée !
+ {% if tournament.should_request_payment and tournament.online_payment_is_mandatory %} +
Vous devez payer votre inscription pour confirmer votre participation.
+ {% endif %} + {% if team.get_confirmation_deadline %} + {% timezone tournament.timezone %} + {% with time_to_confirm=team.get_confirmation_deadline %} + {% now "Y-m-d H:i:s" as current_time_str %} + {% if time_to_confirm %} + {% if time_to_confirm|date:"Y-m-d H:i:s" > current_time_str %} +
Vous devez confirmer votre participation avant le :
+

{{ time_to_confirm|date:"d/m/Y à H:i" }}

+ +

Temps restant: {{ time_to_confirm|timeuntil }}

+ {% else %} +

+ Le délai de confirmation est expiré. Votre place a été proposée à une autre équipe. +

+ {% endif %} + {% endif %} + {% endwith %} + {% endtimezone %} + {% endif %} + {% endif %} + {% if team.call_date %}

Convocation

@@ -109,58 +107,55 @@ {% if tournament.should_request_payment and team.is_in_waiting_list < 0 %}
-

Paiement

{% if team.is_paid %} - {% endif %} {% if team.needs_confirmation and tournament.online_payment_is_mandatory is False %} -
-
- {% csrf_token %} - -
-
+
+
+ {% csrf_token %} + +
+
{% endif %} {% if tournament.is_unregistration_possible %} -
- {% if tournament.is_refund_possible and team.is_paid %} -

- Si vous vous désinscrivez, votre inscription sera remboursée automatiquement sur votre carte bancaire. - {% if tournament.refund_date_limit %} -

Remboursement possible jusqu'au {{ tournament.refund_date_limit|date:"d/m/Y à H:i" }}
- {% endif %} -

+
+ {% if tournament.is_refund_possible and team.is_paid %} +

+ Si vous vous désinscrivez, votre inscription sera remboursée automatiquement sur votre carte bancaire. + {% if tournament.refund_date_limit %} +

Remboursement possible jusqu'au {{ tournament.refund_date_limit|date:"d/m/Y à H:i" }}
{% endif %} - - - {% if team.is_in_waiting_list >= 0 %} - Se retirer de la liste d'attente - {% else %} - Se désinscrire - {% endif %} - +

+ {% endif %} + {% endif %} - +
{% endif %}

{{ tournament.display_name }} {{ tournament.get_federal_age_category_display}}

diff --git a/tournaments/views.py b/tournaments/views.py index 589ec05..2088733 100644 --- a/tournaments/views.py +++ b/tournaments/views.py @@ -1073,16 +1073,16 @@ def confirm_tournament_registration(request, tournament_id): if not team_registrations.exists(): messages.error(request, "Aucune inscription trouvée pour ce tournoi.") - return redirect('tournament_info', tournament_id=tournament_id) + return redirect('tournament-info', tournament_id=tournament_id) team_registration = team_registrations.first() # Confirm registration team_registration.confirm_registration() messages.success(request, "Votre participation est confirmée !") - return redirect('tournament_info', tournament_id=tournament_id) + return redirect('tournament-info', tournament_id=tournament_id) - return redirect('tournament_info', tournament_id=tournament_id) + return redirect('tournament-info', tournament_id=tournament_id) @login_required def proceed_to_payment(request, tournament_id):