improve online register add email generation

online_registration
Raz 11 months ago
parent e5cc96bae6
commit 9b8d464183
  1. 6
      tournaments/models/team_registration.py
  2. 43
      tournaments/models/tournament.py
  3. 2
      tournaments/templates/register_tournament.html
  4. 16
      tournaments/templates/tournaments/tournament_info.html
  5. 63
      tournaments/views.py

@ -119,3 +119,9 @@ class TeamRegistration(models.Model):
def out_of_tournament(self): def out_of_tournament(self):
return self.walk_out or self.unregistered return self.walk_out or self.unregistered
def get_other_player(self, player):
for p in self.playerregistration_set.all():
if p != player:
return p
return None

@ -927,6 +927,8 @@ class Tournament(models.Model):
def online_register_is_enabled(self): def online_register_is_enabled(self):
if self.supposedly_in_progress(): if self.supposedly_in_progress():
return False return False
if self.closed_registration_date is not None:
return False
if self.end_date is not None: if self.end_date is not None:
return False return False
@ -961,6 +963,8 @@ class Tournament(models.Model):
def get_online_registration_status(self): def get_online_registration_status(self):
if self.supposedly_in_progress(): if self.supposedly_in_progress():
return OnlineRegistrationStatus.IN_PROGRESS return OnlineRegistrationStatus.IN_PROGRESS
if self.closed_registration_date is not None:
return OnlineRegistrationStatus.ENDED
if self.end_date is not None: if self.end_date is not None:
return OnlineRegistrationStatus.ENDED_WITH_RESULTS return OnlineRegistrationStatus.ENDED_WITH_RESULTS
@ -997,6 +1001,45 @@ class Tournament(models.Model):
return OnlineRegistrationStatus.OPEN return OnlineRegistrationStatus.OPEN
def is_unregistration_possible(self):
# Check if tournament has started
if self.supposedly_in_progress():
return False
if self.closed_registration_date is not None:
return False
# Check if tournament is finished
if self.end_date is not None:
return False
# Check if registration is closed
if self.registration_date_limit is not None:
if timezone.now() > self.registration_date_limit:
return False
# Otherwise unregistration is allowed
return True
def build_tournament_details_str(self):
tournament_details = []
tournament_details.append(self.level())
if self.category():
tournament_details.append(self.category())
if self.age():
tournament_details.append(self.age())
return " ".join(filter(None, tournament_details))
def build_name_details_str(self):
name_details = []
if self.name:
name_details.append(self.name)
if self.event.name:
name_details.append(self.event.name)
name_str = " - ".join(filter(None, name_details))
if name_str:
name_str = f" {name_str}"
return name_str
class MatchGroup: class MatchGroup:
def __init__(self, name, matches, formatted_schedule): def __init__(self, name, matches, formatted_schedule):

@ -22,7 +22,7 @@
{% if registration_successful %} {% if registration_successful %}
<p>Merci, l'inscription a bien été envoyé au juge-arbitre.</p> <p>Merci, l'inscription a bien été envoyé au juge-arbitre.</p>
<p>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 %} {% else %}
<form method="post"> <form method="post">
{% csrf_token %} {% csrf_token %}

@ -45,6 +45,9 @@
</p> </p>
{% endif %} {% endif %}
<div>{{ tournament.build_tournament_details_str|linebreaksbr }}</div>
<div>{{ tournament.build_name_details_str|linebreaksbr }}</div>
{% if tournament.online_register_is_enabled %} {% if tournament.online_register_is_enabled %}
<p> <p>
@ -128,8 +131,15 @@
<div>Inscrit le {{ team.registration_date }}</div> <div>Inscrit le {{ team.registration_date }}</div>
</p> </p>
{% if tournament.is_unregistration_possible %}
<p> <p>
<div class="margin10">
{% for message in messages %}
<div class="alert alert-{{ message.tags }}">{{ message }}</div>
{% endfor %}
</div>
<a href="{% url 'unregister_tournament' tournament.id %}" <a href="{% url 'unregister_tournament' tournament.id %}"
class="rounded-button destructive-button" class="rounded-button destructive-button"
onclick="return confirm('Êtes-vous sûr de vouloir vous désinscrire ?');"> onclick="return confirm('Êtes-vous sûr de vouloir vous désinscrire ?');">
@ -141,7 +151,9 @@
{% else %} {% else %}
<p> <p>
<div>Vous n'êtes pas le capitaine de l'équipe, la désinscription en ligne n'est pas disponible. Veuillez contacter le JAP ou votre partenaire.</div> <div>Vous n'êtes pas le capitaine de l'équipe, la désinscription en ligne n'est pas disponible. Veuillez contacter le JAP ou votre partenaire.</div>
</p> --> </p>
{% endif %}
-->
{% endif %} {% endif %}
</div> </div>
{% endif %} {% endif %}

@ -770,6 +770,30 @@ def register_tournament(request, tournament_id):
request.session['team_registration'] = [] request.session['team_registration'] = []
registration_successful = True registration_successful = True
# Send confirmation email
tournament_details_str = tournament.build_tournament_details_str()
name_str = tournament.build_name_details_str()
email_subject = f"Confirmation d'inscription au {tournament_details_str}{name_str}"
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)
email_body = f"Bonjour,\n\nVotre inscription au tournoi {tournament_details_str}{name_str} est confirmée."
email_body += f"\n\nDate d'inscription: {inscription_date}"
email_body += f"\n\nÉquipe inscrite: {team_members_str}"
email_body += f"\n\nLe tournoi commencera le {tournament.start_date.strftime('%d/%m/%Y')}"
email_body += f" @ {tournament.event.club.name}"
email_body += f"\n\nVoir les informations sur {request.build_absolute_uri(f'/tournament/{tournament.id}/')}"
email_body += "\n\nPour toute question, veuillez contacter votre juge-arbitre. Si vous n'êtes pas à l'origine de cette inscription, merci de le contacter rapidement.\nCeci est un e-mail automatique, veuillez ne pas y répondre."
email_body += "\n\nCordialement,\n\nPadel Club"
email = EmailMessage(
subject=email_subject,
body=email_body,
to=[team_form.cleaned_data['email']]
)
email.send()
else: else:
add_player_form = AddPlayerForm() add_player_form = AddPlayerForm()
@ -835,17 +859,56 @@ def register_tournament(request, tournament_id):
@login_required @login_required
def unregister_tournament(request, tournament_id): def unregister_tournament(request, tournament_id):
tournament = get_object_or_404(Tournament, id=tournament_id)
if not tournament or not tournament.is_unregistration_possible():
messages.error(request, "Le désistement n'est plus possible pour ce tournoi.")
return redirect('tournament-info', tournament_id=tournament_id)
user_licence_id = request.user.licence_id user_licence_id = request.user.licence_id
if not user_licence_id:
messages.error(request, "Vous ne pouvez pas vous désinscrire car vous n'avez pas de numéro de licence associé.")
return redirect('tournament-info', tournament_id=tournament_id)
player_registration = PlayerRegistration.objects.filter( player_registration = PlayerRegistration.objects.filter(
licence_id__startswith=user_licence_id, licence_id__startswith=user_licence_id,
team_registration__tournament_id=tournament_id team_registration__tournament_id=tournament_id
).first() # Get the first match, if any ).first() # Get the first match, if any
other_player = None
if player_registration: if player_registration:
team_registration = player_registration.team_registration # Get the related TeamRegistration team_registration = player_registration.team_registration # Get the related TeamRegistration
other_player = team_registration.get_other_player(player_registration)
team_registration.delete() # Delete the team registration team_registration.delete() # Delete the team registration
else:
messages.error(request, "La désincription a échouée. Veuillez contacter le juge-arbitre.")
return redirect('tournament-info', tournament_id=tournament_id)
request.session['team_registration'] = [] request.session['team_registration'] = []
# Get the tournament information and player details before deleting
if tournament and request.user.email: # Ensure we have valid tournament and user email
tournament_details_str = tournament.build_tournament_details_str()
name_str = tournament.build_name_details_str()
email_subject = f"Confirmation de désistement au {tournament_details_str}{name_str}"
email_body = f"Bonjour,\n\nVous venez de vous désinscrire du tournoi {tournament_details_str}{name_str}"
email_body += f" du {tournament.start_date.strftime('%d/%m/%Y')}"
email_body += f" au {tournament.event.club.name}"
if other_player is not None:
email_body += f"\n\nVous étiez inscrit avec {other_player.name()}, n'oubliez pas de prévenir votre partenaire."
email_body += f"\n\nVoir les informations sur {request.build_absolute_uri(f'/tournament/{tournament.id}/')}"
email_body += "\n\nPour toute question, veuillez contacter votre juge-arbitre. Si vous n'êtes pas à l'origine de ce désistement, merci de le contacter rapidement.\nCeci est un e-mail automatique, veuillez ne pas y répondre."
email_body += "\n\nCordialement,\n\nPadel Club."
email = EmailMessage(
subject=email_subject,
body=email_body,
to=[request.user.email]
)
email.send()
return redirect('tournament-info', tournament_id=tournament_id) return redirect('tournament-info', tournament_id=tournament_id)

Loading…
Cancel
Save