add a mail notification to the umpire when team unregister and display canceled status for a team status in priority

sync_v2
Raz 6 months ago
parent 525681d7ae
commit ffdb5ce74c
  1. 10
      tournaments/models/player_registration.py
  2. 9
      tournaments/models/team_registration.py
  3. 7
      tournaments/models/tournament.py
  4. 43
      tournaments/services/email_service.py
  5. 5
      tournaments/services/tournament_unregistration.py
  6. 8
      tournaments/templates/tournaments/tournament_info.html

@ -111,6 +111,16 @@ class PlayerRegistration(SideStoreModel):
tournament = self.team_registration.tournament tournament = self.team_registration.tournament
tournament_status_team_count = tournament.get_tournament_status_team_count() 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 = { status = {
'header': "Équipes", 'header': "Équipes",
'position': tournament_status_team_count, 'position': tournament_status_team_count,

@ -500,3 +500,12 @@ class TeamRegistration(SideStoreModel):
tournament, tournament,
TeamEmailType.REQUIRES_TIME_CONFIRMATION 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

@ -974,8 +974,8 @@ class Tournament(BaseModel):
timezoned_datetime -= timedelta(hours=hour_delta) timezoned_datetime -= timedelta(hours=hour_delta)
return now >= timezoned_datetime return now >= timezoned_datetime
def will_start_soon(self): def will_start_soon(self, hour_delta=2):
return self.has_started(hour_delta=2) return self.has_started(hour_delta=hour_delta)
def supposedly_in_progress(self): def supposedly_in_progress(self):
# end = self.start_date + timedelta(days=self.day_duration + 1) # end = self.start_date + timedelta(days=self.day_duration + 1)
@ -1214,6 +1214,9 @@ class Tournament(BaseModel):
if self.supposedly_in_progress(): if self.supposedly_in_progress():
return False return False
if self.will_start_soon(12):
return False
if self.closed_registration_date is not None: if self.closed_registration_date is not None:
return False return False

@ -606,6 +606,49 @@ class TournamentEmailService:
# If there's only one player, just send them the notification # If there's only one player, just send them the notification
TournamentEmailService.notify(players[0], None, tournament, message_type) 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'<a href="{absolute_url}">{link_text}</a>'
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 @staticmethod
def _build_payment_info(tournament, team_registration): def _build_payment_info(tournament, team_registration):
""" """

@ -1,9 +1,8 @@
from django.contrib import messages from django.contrib import messages
from django.utils import timezone from django.utils import timezone
from ..models import PlayerRegistration, UnregisteredTeam, UnregisteredPlayer, PlayerPaymentType from ..models import PlayerRegistration, UnregisteredTeam, UnregisteredPlayer, PlayerPaymentType
from ..utils.licence_validator import LicenseValidator
from ..services.payment_service import PaymentService from ..services.payment_service import PaymentService
from ..services.email_service import TournamentEmailService from ..services.email_service import TournamentEmailService, TeamEmailType
class TournamentUnregistrationService: class TournamentUnregistrationService:
def __init__(self, request, tournament): def __init__(self, request, tournament):
@ -96,6 +95,8 @@ class TournamentUnregistrationService:
registered_online=player.registered_online registered_online=player.registered_online
) )
TournamentEmailService.notify_umpire(team_registration, team_registration.tournament, TeamEmailType.UNREGISTERED)
def _find_player_registration(self): def _find_player_registration(self):
# First check if we can find the player registration directly by user # First check if we can find the player registration directly by user
if self.request.user.is_authenticated: if self.request.user.is_authenticated:

@ -121,7 +121,7 @@
</div> </div>
{% endif %} {% endif %}
{% if tournament.is_unregistration_possible %} {% if tournament.is_unregistration_possible and team.is_unregistration_possible %}
<div class="topmargin20"> <div class="topmargin20">
{% if tournament.is_refund_possible and team.is_paid %} {% if tournament.is_refund_possible and team.is_paid %}
<p class="minor info"> <p class="minor info">
@ -142,6 +142,12 @@
{% endif %} {% endif %}
</a> </a>
</div> </div>
{% else %}
<div class="topmargin20">
<p class="minor info">
La désincription en ligne n'est plus possible. Veuillez contacter directement le juge-arbitre si besoin.
</p>
</div>
{% endif %} {% endif %}
</div> </div>
</div> </div>

Loading…
Cancel
Save