diff --git a/tournaments/models/player_registration.py b/tournaments/models/player_registration.py index e7f3546..59141b0 100644 --- a/tournaments/models/player_registration.py +++ b/tournaments/models/player_registration.py @@ -111,6 +111,16 @@ class PlayerRegistration(SideStoreModel): tournament = self.team_registration.tournament tournament_status_team_count = tournament.get_tournament_status_team_count() + + if tournament.is_canceled(): + return { + 'header': "Équipes", + 'position': tournament_status_team_count, + 'display_box': True, + 'box_class': 'light-red', + 'short_label': 'annulé' + } + status = { 'header': "Équipes", 'position': tournament_status_team_count, diff --git a/tournaments/models/team_registration.py b/tournaments/models/team_registration.py index 76ce959..83f4b06 100644 --- a/tournaments/models/team_registration.py +++ b/tournaments/models/team_registration.py @@ -500,3 +500,12 @@ class TeamRegistration(SideStoreModel): tournament, TeamEmailType.REQUIRES_TIME_CONFIRMATION ) + + def is_unregistration_possible(self): + if self.call_date is not None: + return False + if self.bracket_position is not None: + return False + if self.group_stage_position is not None: + return False + return True diff --git a/tournaments/models/tournament.py b/tournaments/models/tournament.py index 074d21f..6ddcafa 100644 --- a/tournaments/models/tournament.py +++ b/tournaments/models/tournament.py @@ -974,8 +974,8 @@ class Tournament(BaseModel): timezoned_datetime -= timedelta(hours=hour_delta) return now >= timezoned_datetime - def will_start_soon(self): - return self.has_started(hour_delta=2) + def will_start_soon(self, hour_delta=2): + return self.has_started(hour_delta=hour_delta) def supposedly_in_progress(self): # end = self.start_date + timedelta(days=self.day_duration + 1) @@ -1214,6 +1214,9 @@ class Tournament(BaseModel): if self.supposedly_in_progress(): return False + if self.will_start_soon(12): + return False + if self.closed_registration_date is not None: return False diff --git a/tournaments/services/email_service.py b/tournaments/services/email_service.py index f3398a4..c7a572b 100644 --- a/tournaments/services/email_service.py +++ b/tournaments/services/email_service.py @@ -606,6 +606,49 @@ class TournamentEmailService: # If there's only one player, just send them the notification TournamentEmailService.notify(players[0], None, tournament, message_type) + @staticmethod + def notify_umpire(team, tournament, message_type): + # Notify the umpire if needed + umpire_email = tournament.umpire_mail() + if umpire_email: + tournament_details_str = tournament.build_tournament_details_str() + + federal_level_category = FederalLevelCategory(tournament.federal_level_category) + tournament_word = federal_level_category.localized_word() + tournament_prefix_that = federal_level_category.localized_prefix_that() + + body_parts = [ + "Email automatique suite à une désinscription", + f"\n\n{tournament_details_str} | {tournament.formatted_start_date()} | {tournament.event.club.name}" + "\n\nL'équipe ci-dessous a annulé son inscription via le site PadelClub :", + ] + + for player in team.players_sorted_by_rank: + body_parts.append( + f"\n{player.name()}" + ) + + absolute_url = f"https://padelclub.app/tournament/{tournament.id}/info" + link_text = f"informations sur {tournament_prefix_that}{tournament_word} sur https://padelclub.app" + absolute_url = f'{link_text}' + + body_parts.append( + f"\n\nVoir les {absolute_url}", + ) + + body_parts.extend([ + "\n\nCeci est un e-mail automatique." + ]) + + email_body = "".join(body_parts) + + if email_body is None: + return + + topic = message_type.email_topic(tournament.federal_level_category) + email_subject = TournamentEmailService.email_subject(tournament, topic) + TournamentEmailService._send_email(umpire_email, email_subject, email_body) + @staticmethod def _build_payment_info(tournament, team_registration): """ diff --git a/tournaments/services/tournament_unregistration.py b/tournaments/services/tournament_unregistration.py index f143aee..4d4869b 100644 --- a/tournaments/services/tournament_unregistration.py +++ b/tournaments/services/tournament_unregistration.py @@ -1,9 +1,8 @@ from django.contrib import messages from django.utils import timezone from ..models import PlayerRegistration, UnregisteredTeam, UnregisteredPlayer, PlayerPaymentType -from ..utils.licence_validator import LicenseValidator from ..services.payment_service import PaymentService -from ..services.email_service import TournamentEmailService +from ..services.email_service import TournamentEmailService, TeamEmailType class TournamentUnregistrationService: def __init__(self, request, tournament): @@ -96,6 +95,8 @@ class TournamentUnregistrationService: registered_online=player.registered_online ) + TournamentEmailService.notify_umpire(team_registration, team_registration.tournament, TeamEmailType.UNREGISTERED) + def _find_player_registration(self): # First check if we can find the player registration directly by user if self.request.user.is_authenticated: diff --git a/tournaments/templates/tournaments/tournament_info.html b/tournaments/templates/tournaments/tournament_info.html index d190335..2dcd190 100644 --- a/tournaments/templates/tournaments/tournament_info.html +++ b/tournaments/templates/tournaments/tournament_info.html @@ -121,26 +121,32 @@ {% endif %} - {% if tournament.is_unregistration_possible %} -
- Si vous vous désinscrivez, votre inscription sera remboursée automatiquement sur votre carte bancaire. - {% if tournament.refund_date_limit %} -