@ -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 ' , ' <br> ' )
return f """
< html >
< body >
{ html_content }
< / body >
< / html >
"""
@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 ' <a href= " { absolute_url } " > { link_text } </a> '
body_parts . extend ( [
f " \n Date d ' inscription: { inscription_date } " ,
f " \n Équipe inscrite: { team_members_str } " ,
f " \n Le tournoi commencera le { tournament . start_date . strftime ( ' %d / % m/ % Y ' ) } au club { tournament . event . club . name } " ,
f " \n Voir les informations sur { request . build_ absolute_uri ( f ' /tournament/ { tournament . id } / ' ) } " ,
f " \n Voir les { absolute_url } " ,
" \n Pour 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 } " ,
" \n Ceci 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 ' <a href= " { absolute_url } " > { link_text } </a> '
if other_player is not None :
body_parts . append (
f " \n Voici le partenaire indiqué dans l ' inscription : { other_player . name ( ) } , n ' oubliez pas de le prévenir. "
)
body_parts . append (
" \n Si vous n ' êtes plus disponible pour participer à ce tournoi, cliquez sur ce lien ou contactez rapidement le juge-arbitre. "
f " \n { absolute_url } "