handle automatic waiting list email

online_registration
Raz 11 months ago
parent febb571788
commit 786cdb5b04
  1. 7
      tournaments/models/tournament.py
  2. 69
      tournaments/services/email_service.py
  3. 56
      tournaments/services/tournament_unregistration.py
  4. 33
      tournaments/signals.py
  5. 2
      tournaments/templates/register_tournament.html

@ -1160,6 +1160,13 @@ class Tournament(models.Model):
def min_player_rank(self):
return FederalLevelCategory.min_player_rank(self.federal_level_category, self.federal_category, self.federal_age_category)
def first_waiting_list_team(self):
teams = self.teams(True)
waiting_teams = [team for team in teams if team.stage == "Attente"]
if waiting_teams:
return waiting_teams[0]
return None
class MatchGroup:
def __init__(self, name, matches, formatted_schedule):
self.name = name

@ -1,5 +1,6 @@
from django.core.mail import EmailMessage
from django.utils import timezone
from django.urls import reverse
class TournamentEmailService:
@staticmethod
@ -38,14 +39,13 @@ class TournamentEmailService:
return base_subject
@staticmethod
def _build_email_body(request, tournament, team_registration, tournament_details_str,
name_str, waiting_list_position):
def _build_email_body(request, tournament, team_registration, tournament_details_str, name_str, waiting_list_position):
inscription_date = timezone.now().strftime("%d/%m/%Y à %H:%M")
team_members = [player.name() for player in team_registration.playerregistration_set.all()]
team_members_str = " et ".join(team_members)
body_parts = []
body_parts.append(f"Bonjour,\n")
body_parts.append("Bonjour,\n")
if waiting_list_position >= 0:
body_parts.append(f"Votre inscription en liste d'attente du tournoi {tournament_details_str} {name_str} est confirmée.")
@ -55,7 +55,7 @@ class TournamentEmailService:
body_parts.extend([
f"\nDate d'inscription: {inscription_date}",
f"\nÉquipe inscrite: {team_members_str}",
f"\nLe tournoi commencera le {tournament.start_date.strftime('%d/%m/%Y')} @ {tournament.event.club.name}",
f"\nLe tournoi commencera le {tournament.start_date.strftime('%d/%m/%Y')} au club {tournament.event.club.name}",
f"\nVoir les informations sur {request.build_absolute_uri(f'/tournament/{tournament.id}/')}",
"\nPour toute question, veuillez contacter votre juge-arbitre. Si vous n'êtes pas à l'origine de cette inscription, merci de le contacter rapidement.",
f"\n{tournament.event.creator.full_name()}\n{tournament.event.creator.email}",
@ -66,12 +66,35 @@ class TournamentEmailService:
return "\n".join(body_parts)
@staticmethod
def send_unregistration_confirmation(captain, tournament, other_player):
def send_unregistration_confirmation(request, captain, tournament, other_player):
tournament_details_str = tournament.build_tournament_details_str()
name_str = tournament.build_name_details_str()
email_subject = f"Confirmation de désistement du tournoi {tournament_details_str} {name_str}"
email_body = TournamentEmailService._build_unregistration_email_body(
request,
tournament,
captain,
tournament_details_str,
name_str,
other_player
)
email = EmailMessage(
subject=email_subject,
body=email_body,
to=[captain.email]
)
email.send()
@staticmethod
def send_out_of_waiting_list_confirmation(request, captain, tournament, other_player):
tournament_details_str = tournament.build_tournament_details_str()
name_str = tournament.build_name_details_str()
email_subject = f"Participation au tournoi {tournament_details_str} {name_str}"
email_body = TournamentEmailService._buil_out_of_waiting_list_email_body(
request,
tournament,
captain,
tournament_details_str,
@ -87,10 +110,10 @@ class TournamentEmailService:
email.send()
@staticmethod
def _build_unregistration_email_body(tournament, captain, tournament_details_str, name_str, other_player):
def _build_unregistration_email_body(request, tournament, captain, tournament_details_str, name_str, other_player):
body_parts = [
"Bonjour,\n",
f"Votre inscription au tournoi {tournament_details_str} {name_str} du {tournament.start_date.strftime('%d/%m/%Y')} @ {tournament.event.club.name} a été annulée"
f"Votre inscription au tournoi {tournament_details_str} {name_str}, prévu le {tournament.start_date.strftime('%d/%m/%Y')} au club {tournament.event.club.name} a été annulée"
]
if other_player is not None:
@ -98,6 +121,10 @@ class TournamentEmailService:
f"\n\nVous étiez inscrit avec {other_player.name()}, n'oubliez pas de prévenir votre partenaire."
)
body_parts.extend([
f"\n\nVoir les informations du tournoi sur {request.build_absolute_uri(f'/tournament/{tournament.id}/')}",
])
body_parts.extend([
"\n\nPour toute question, veuillez contacter votre juge-arbitre. "
"Si vous n'êtes pas à l'origine de cette inscription, merci de le contacter rapidement.",
@ -106,3 +133,31 @@ class TournamentEmailService:
])
return "".join(body_parts)
@staticmethod
def _buil_out_of_waiting_list_email_body(request, tournament, captain, tournament_details_str, name_str, other_player):
body_parts = [
"Bonjour,\n",
f"Suite au désistement d'une paire, vous êtes maintenant inscrit au tournoi {tournament_details_str} {name_str}, prévu le {tournament.start_date.strftime('%d/%m/%Y')} au club {tournament.event.club.name}"
]
unregister_url = reverse('unregister-tournament', args=[tournament.id])
absolute_url = request.build_absolute_uri(unregister_url)
if other_player is not None:
body_parts.append(
f"\nVoici le partenaire indiqué dans l'inscription : {other_player.name()}, n'oubliez pas de le prévenir."
)
body_parts.append(
"\nSi vous n'êtes plus disponible pour participer à ce tournoi, cliquez sur ce lien ou contactez rapidement le juge-arbitre."
f"\n{absolute_url}"
)
body_parts.extend([
f"\n\n{tournament.event.creator.full_name()}\n{tournament.event.creator.email}",
"\n\nCeci est un e-mail automatique, veuillez ne pas y répondre."
])
return "".join(body_parts)

@ -47,6 +47,62 @@ class TournamentUnregistrationService:
def _delete_registered_team(self):
team_registration = self.player_registration.team_registration
tournament=team_registration.tournament
print("Unregistering team from tournament")
unregistered_team = UnregisteredTeam.objects.create(
tournament=tournament,
unregistration_date=timezone.now(),
)
captain = None
other_player = None
for player in team_registration.playerregistration_set.all():
if player.captain is True:
captain = player
else:
other_player = player
UnregisteredPlayer.objects.create(
unregistered_team=unregistered_team,
first_name=player.first_name,
last_name=player.last_name,
licence_id=player.licence_id,
)
first_waiting_list_team = tournament.first_waiting_list_team()
if first_waiting_list_team:
waiting_captain = None
waiting_other_player = None
for player in first_waiting_list_team.playerregistration_set.all():
if player.captain is True:
waiting_captain = player
else:
waiting_other_player = player
if waiting_captain and waiting_captain.source is not PlayerDataSource.ONLINE_REGISTRATION and not waiting_captain.email:
return
TournamentEmailService.send_out_of_waiting_list_confirmation(
self.request,
waiting_captain,
tournament,
waiting_other_player
)
if captain and captain.source is not PlayerDataSource.ONLINE_REGISTRATION and not captain.email:
return
TournamentEmailService.send_unregistration_confirmation(
self.request,
captain,
tournament,
other_player
)
team_registration.delete()
def _cleanup_session(self):

@ -57,36 +57,3 @@ def send_discord_message(webhook_url, content):
raise ValueError(
f'Error sending message to Discord webhook: {response.status_code}, {response.text}'
)
@receiver(pre_delete, sender=TeamRegistration)
def unregister_team(sender, instance, **kwargs):
team_registration = instance
tournament=instance.tournament
print("Unregistering team from tournament")
unregistered_team = UnregisteredTeam.objects.create(
tournament=tournament,
unregistration_date=timezone.now(),
)
captain = None
other_player = None
for player in team_registration.playerregistration_set.all():
if player.captain is True:
captain = player
else:
other_player = player
UnregisteredPlayer.objects.create(
unregistered_team=unregistered_team,
first_name=player.first_name,
last_name=player.last_name,
licence_id=player.licence_id,
)
if captain and captain.source is not PlayerDataSource.ONLINE_REGISTRATION and not captain.email:
return
TournamentEmailService.send_unregistration_confirmation(
captain,
tournament,
other_player
)

@ -23,7 +23,7 @@
{% if registration_successful %}
<p>Merci, l'inscription a bien été envoyée au juge-arbitre.</p>
<p style="text-align: justify;">
Un email de confirmation a été envoyée à {{ user.email }} pour confirmer votre inscription. Pensez à vérifier vos spams si vous ne recevez pas l'email. En cas de problème, contactez le juge-arbitre.
Un email de confirmation a été envoyé à {{ user.email }} pour confirmer votre inscription. Pensez à vérifier vos spams si vous ne recevez pas l'email. En cas de problème, contactez le juge-arbitre.
</p>
{% else %}
<form method="post">

Loading…
Cancel
Save