diff --git a/tournaments/models/tournament.py b/tournaments/models/tournament.py
index 7cfd1a6..ff334c5 100644
--- a/tournaments/models/tournament.py
+++ b/tournaments/models/tournament.py
@@ -1172,6 +1172,9 @@ class Tournament(models.Model):
def first_waiting_list_team(self):
teams = self.teams(True)
+
+ if len(teams)<=self.team_count:
+ return None
waiting_teams = [team for team in teams if team.stage == "Attente"]
if waiting_teams:
return waiting_teams[0].team_registration
diff --git a/tournaments/services/email_service.py b/tournaments/services/email_service.py
index c205e25..aa2308c 100644
--- a/tournaments/services/email_service.py
+++ b/tournaments/services/email_service.py
@@ -3,6 +3,17 @@ from django.utils import timezone
from django.urls import reverse
class TournamentEmailService:
+ @staticmethod
+ def _convert_newlines_to_html(text):
+ html_content = text.replace('\n', '
')
+ return f"""
+
+
+ {html_content}
+
+
+ """
+
@staticmethod
def send_registration_confirmation(request, tournament, team_registration, waiting_list_position):
tournament_details_str = tournament.build_tournament_details_str()
@@ -25,9 +36,11 @@ class TournamentEmailService:
email = EmailMessage(
subject=email_subject,
- body=email_body,
+ body=TournamentEmailService._convert_newlines_to_html(email_body),
to=[request.user.email]
)
+
+ email.content_subtype = "html"
email.send()
@staticmethod
@@ -52,11 +65,15 @@ class TournamentEmailService:
else:
body_parts.append(f"Votre inscription au tournoi {tournament_details_str} {name_str} est confirmée.")
+ absolute_url = f"{request.build_absolute_uri(f'/tournament/{tournament.id}/')}"
+ link_text = "informations sur le tournoi"
+ absolute_url = f'{link_text}'
+
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')} au club {tournament.event.club.name}",
- f"\nVoir les informations sur {request.build_absolute_uri(f'/tournament/{tournament.id}/')}",
+ f"\nVoir les {absolute_url}",
"\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}",
"\nCeci est un e-mail automatique, veuillez ne pas y répondre.",
@@ -81,9 +98,11 @@ class TournamentEmailService:
email = EmailMessage(
subject=email_subject,
- body=email_body,
+ body=TournamentEmailService._convert_newlines_to_html(email_body),
to=[captain.email]
)
+
+ email.content_subtype = "html"
email.send()
if other_player.email is not None:
@@ -97,9 +116,11 @@ class TournamentEmailService:
email = EmailMessage(
subject=email_subject,
- body=email_body,
+ body=TournamentEmailService._convert_newlines_to_html(email_body),
to=[other_player.email]
)
+
+ email.content_subtype = "html"
email.send()
@staticmethod
@@ -118,10 +139,11 @@ class TournamentEmailService:
email = EmailMessage(
subject=email_subject,
- body=email_body,
+ body=TournamentEmailService._convert_newlines_to_html(email_body),
to=[captain.email]
)
+ email.content_subtype = "html"
email.send()
if other_player.email is not None:
@@ -135,11 +157,12 @@ class TournamentEmailService:
email = EmailMessage(
subject=email_subject,
- body=email_body,
+ body=TournamentEmailService._convert_newlines_to_html(email_body),
to=[other_player.email]
)
- email.send()
+ email.content_subtype = "html"
+ email.send()
@staticmethod
def _build_unregistration_email_body(tournament, captain, tournament_details_str, name_str, other_player):
@@ -169,15 +192,15 @@ class TournamentEmailService:
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}"
]
- # Make it an absolute URL by adding the domain
- absolute_url = f"https://xlr.alwaysdata.net/tournament/{tournament.id}/info" # Replace with your domain
+ absolute_url = f"https://xlr.alwaysdata.net/tournament/{tournament.id}/info"
+ link_text = "informations sur le tournoi"
+ absolute_url = f'{link_text}'
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}"