fix signal and success page

shop
Raz 8 months ago
parent 1dd69b9519
commit b6624ca2ca
  1. 6
      tournaments/repositories.py
  2. 74
      tournaments/services/email_service.py
  3. 22
      tournaments/services/tournament_registration.py
  4. 24
      tournaments/signals.py
  5. 23
      tournaments/templates/registration/activation_failed.html
  6. 18
      tournaments/templates/registration/activation_success.html
  7. 2
      tournaments/templates/tournaments/tournament_info.html
  8. 2
      tournaments/urls.py
  9. 12
      tournaments/views.py

@ -53,12 +53,10 @@ class TournamentRegistrationRepository:
rank=rank, rank=rank,
computed_rank=computed_rank, computed_rank=computed_rank,
licence_id=player_data['licence_id'], licence_id=player_data['licence_id'],
email=player_data.get('email'),
phone_number=player_data.get('mobile_number'),
) )
if is_captain is True:
player_registration.email=team_form_data['email']
player_registration.phone_number=team_form_data['mobile_number']
player_registration.save() player_registration.save()
team_registration.set_weight() team_registration.set_weight()

@ -4,6 +4,8 @@ from django.urls import reverse
from enum import Enum from enum import Enum
class TeamEmailType(Enum): class TeamEmailType(Enum):
REGISTERED = "registered"
WAITING_LIST = "waiting_list"
UNREGISTERED = "unregistered" UNREGISTERED = "unregistered"
OUT_OF_WAITING_LIST = "out_of_waiting_list" OUT_OF_WAITING_LIST = "out_of_waiting_list"
TOURNAMENT_CANCELED = "tournament_canceled" TOURNAMENT_CANCELED = "tournament_canceled"
@ -16,6 +18,8 @@ class TeamEmailType(Enum):
def email_subject(self) -> str: def email_subject(self) -> str:
subjects = { subjects = {
self.REGISTERED: "Participation confirmée",
self.WAITING_LIST: "Liste d'attente",
self.UNREGISTERED: "Désistement", self.UNREGISTERED: "Désistement",
self.OUT_OF_WAITING_LIST: "Participation confirmée", self.OUT_OF_WAITING_LIST: "Participation confirmée",
self.TOURNAMENT_CANCELED: "Tournoi annulé", self.TOURNAMENT_CANCELED: "Tournoi annulé",
@ -47,52 +51,37 @@ class TournamentEmailService:
@staticmethod @staticmethod
def send_registration_confirmation(request, tournament, team_registration, waiting_list_position): def send_registration_confirmation(request, tournament, team_registration, waiting_list_position):
tournament_details_str = tournament.build_tournament_details_str()
email_subject = TournamentEmailService._build_email_subject(
tournament,
tournament_details_str,
waiting_list_position
)
email_body = TournamentEmailService._build_email_body(
request,
tournament,
team_registration,
tournament_details_str,
waiting_list_position
)
TournamentEmailService._send_email(request.user.email, email_subject, email_body)
@staticmethod
def _build_email_subject(tournament, tournament_details_str, waiting_list_position):
if waiting_list_position >= 0: if waiting_list_position >= 0:
base_subject = "Liste d'attente" TournamentEmailService.notify_team(team_registration, tournament, TeamEmailType.WAITING_LIST)
else: else:
base_subject = "Participation confirmée" TournamentEmailService.notify_team(team_registration, tournament, TeamEmailType.REGISTERED)
return TournamentEmailService.email_subject(tournament, base_subject)
@staticmethod @staticmethod
def _build_email_body(request, tournament, team_registration, tournament_details_str, waiting_list_position): def _build_registration_confirmation_email_body(tournament, captain, tournament_details_str, other_player):
inscription_date = team_registration.local_registration_date().strftime("%d/%m/%Y à %H:%M") return TournamentEmailService._build_registration_email_body(tournament, captain, tournament_details_str, other_player, False)
team_members = [player.name() for player in team_registration.playerregistration_set.all()]
team_members_str = " et ".join(team_members)
@staticmethod
def _build_waiting_list_confirmation_email_body(tournament, captain, tournament_details_str, other_player):
return TournamentEmailService._build_registration_email_body(tournament, captain, tournament_details_str, other_player, True)
@staticmethod
def _build_registration_email_body(tournament, captain, tournament_details_str, other_player, waiting_list):
inscription_date = captain.team_registration.local_registration_date().strftime("%d/%m/%Y à %H:%M")
body_parts = [] body_parts = []
body_parts.append("Bonjour,\n") body_parts.append("Bonjour,\n")
if waiting_list_position >= 0: if waiting_list:
body_parts.append(f"Votre inscription en liste d'attente du tournoi {tournament_details_str} est confirmée.") body_parts.append(f"Votre inscription en liste d'attente du tournoi {tournament_details_str} est confirmée.")
else: else:
body_parts.append(f"Votre inscription au tournoi {tournament_details_str} est confirmée.") body_parts.append(f"Votre inscription au tournoi {tournament_details_str} est confirmée.")
absolute_url = f"{request.build_absolute_uri(f'/tournament/{tournament.id}/')}" absolute_url = f"https://padelclub.app/tournament/{tournament.id}/info"
link_text = "informations sur le tournoi" link_text = "informations sur le tournoi"
absolute_url = f'<a href="{absolute_url}">{link_text}</a>' absolute_url = f'<a href="{absolute_url}">{link_text}</a>'
body_parts.extend([ body_parts.extend([
f"\nDate d'inscription: {inscription_date}", f"\nDate d'inscription: {inscription_date}",
f"\nÉquipe inscrite: {team_members_str}", f"\nÉquipe inscrite: {captain.name()} et {other_player.name()}",
f"\nLe tournoi commencera le {tournament.formatted_start_date()} au club {tournament.event.club.name}", f"\nLe tournoi commencera le {tournament.formatted_start_date()} au club {tournament.event.club.name}",
f"\nVoir les {absolute_url}", 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.", "\nPour toute question, veuillez contacter votre juge-arbitre. Si vous n'êtes pas à l'origine de cette inscription, merci de le contacter rapidement.",
@ -343,6 +332,7 @@ class TournamentEmailService:
@staticmethod @staticmethod
def notify(captain, other_player, tournament, message_type: TeamEmailType): def notify(captain, other_player, tournament, message_type: TeamEmailType):
print("TournamentEmailService.notify", captain.email, captain.registered_online, tournament, message_type)
if not captain or not captain.registered_online or not captain.email: if not captain or not captain.registered_online or not captain.email:
return return
@ -360,8 +350,16 @@ class TournamentEmailService:
TournamentEmailService._send_email(captain.email, email_subject, email_body) TournamentEmailService._send_email(captain.email, email_subject, email_body)
@staticmethod @staticmethod
def _build_email_content(message_type, recipient, tournament, tournament_details_str, other_player): def _build_email_content(message_type, recipient, tournament, tournament_details_str, other_player, request=None, waiting_list_position=None):
if message_type == TeamEmailType.OUT_OF_WAITING_LIST: if message_type == TeamEmailType.REGISTERED:
body = TournamentEmailService._build_registration_confirmation_email_body(
tournament, recipient, tournament_details_str, other_player
)
elif message_type == TeamEmailType.WAITING_LIST:
body = TournamentEmailService._build_waiting_list_confirmation_email_body(
tournament, recipient, tournament_details_str, other_player
)
elif message_type == TeamEmailType.OUT_OF_WAITING_LIST:
body = TournamentEmailService._build_out_of_waiting_list_email_body( body = TournamentEmailService._build_out_of_waiting_list_email_body(
tournament, recipient, tournament_details_str, other_player tournament, recipient, tournament_details_str, other_player
) )
@ -415,24 +413,14 @@ class TournamentEmailService:
@staticmethod @staticmethod
def notify_team(team, tournament, message_type: TeamEmailType): def notify_team(team, tournament, message_type: TeamEmailType):
captain = None
other_player = None
for player in team.playerregistration_set.all():
if player.captain:
captain = player
else:
other_player = player
if captain:
TournamentEmailService.notify(captain, other_player, tournament, message_type)
else:
# Notify both players separately if there is no captain or the captain is unavailable # Notify both players separately if there is no captain or the captain is unavailable
players = list(team.playerregistration_set.all()) players = list(team.playerregistration_set.all())
if len(players) == 2: if len(players) == 2:
print("TournamentEmailService.notify_team 2p", team)
first_player, second_player = players first_player, second_player = players
TournamentEmailService.notify(first_player, second_player, tournament, message_type) TournamentEmailService.notify(first_player, second_player, tournament, message_type)
TournamentEmailService.notify(second_player, first_player, tournament, message_type) TournamentEmailService.notify(second_player, first_player, tournament, message_type)
elif len(players) == 1: elif len(players) == 1:
print("TournamentEmailService.notify_team 1p", team)
# 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)

@ -290,6 +290,28 @@ class TournamentRegistrationService:
'phone': None, 'phone': None,
}) })
from django.contrib.auth import get_user_model
User = get_user_model()
# Get the license ID from player_data
licence_id = player_data.get('licence_id')
validator = LicenseValidator(licence_id)
if validator and validator.stripped_license:
try:
# Try to find a user with matching license
user_with_same_license = User.objects.get(licence_id__icontains=validator.stripped_license)
# If found, update the email and phone
if user_with_same_license:
player_data.update({
'email': user_with_same_license.email,
'phone': user_with_same_license.phone
})
print(f"Found user with license {licence_id}, updated email and phone")
except User.DoesNotExist:
# No user found with this license, continue with None email and phone
pass
def _handle_first_tournament_case(self, data): def _handle_first_tournament_case(self, data):
print("_handle_first_tournament_case", data) print("_handle_first_tournament_case", data)
if data: if data:

@ -60,29 +60,7 @@ def notify_team(team, tournament, message_type):
if tournament.supposedly_in_progress(): if tournament.supposedly_in_progress():
return return
captain = None TournamentEmailService.notify_team(team, tournament, message_type)
other_player = None
for player in team.playerregistration_set.all():
if player.captain:
captain = player
else:
other_player = player
if captain:
TournamentEmailService.notify(captain, other_player, tournament, message_type)
if not captain.registered_online or not captain.email:
TournamentEmailService.notify(other_player, captain, tournament, message_type)
else:
# Notify both players separately if there is no captain or the captain is unavailable
players = list(team.playerregistration_set.all())
if len(players) == 2:
first_player, second_player = players
TournamentEmailService.notify(first_player, second_player, tournament, message_type)
TournamentEmailService.notify(second_player, first_player, tournament, message_type)
elif len(players) == 1:
# If there's only one player, just send them the notification
TournamentEmailService.notify(players[0], None, tournament, message_type)
@receiver(pre_delete, sender=TeamRegistration) @receiver(pre_delete, sender=TeamRegistration)
def unregister_team(sender, instance, **kwargs): def unregister_team(sender, instance, **kwargs):

@ -0,0 +1,23 @@
{% extends 'tournaments/base.html' %}
{% block head_title %} Activation {% endblock %}
{% block first_title %} Padel Club {% endblock %}
{% block second_title %} Activation {% endblock %}
{% block content %}
{% load static %}
{% load tz %}
<div class="grid-x">
<div class="bubble">
<div class="cell medium-6 large-6 my-block">
<label class="title">Lien d'Activation Invalide</label>
<p>Le lien d'activation est invalide ou a expiré.</p>
<div>
<a href="{% url 'index' %}" class="btn styled-link">Aller à la page d'accueil</a>
</div>
<div>
<a href="mailto:support@padelclub.com" class="btn styled-link">Contacter le support</a>
</div>
</div>
</div>
{% endblock %}

@ -0,0 +1,18 @@
{% extends 'tournaments/base.html' %}
{% block head_title %} Activation {% endblock %}
{% block first_title %} Padel Club {% endblock %}
{% block second_title %} Activation {% endblock %}
{% block content %}
{% load static %}
{% load tz %}
<div class="grid-x">
<div class="bubble">
<div class="cell medium-6 large-6 my-block">
<label class="title">Compte Activé avec Succès !</label>
<p>Votre compte a été activé et vous êtes maintenant connecté.</p>
<a href="{% url 'index' %}" class="btn styled-link">Aller à la page d'accueil</a>
</div>
</div>
{% endblock %}

@ -169,6 +169,8 @@
<p> <p>
<div> <div>
Vous avez besoin d'un compte Padel Club pour pouvoir vous inscrire en ligne. Vous avez besoin d'un compte Padel Club pour pouvoir vous inscrire en ligne.
</div>
<div>
<a href="{% url 'signup' %}?next={{ request.path }}" class="styled-link">Créer le tout de suite !</a> <a href="{% url 'signup' %}?next={{ request.path }}" class="styled-link">Créer le tout de suite !</a>
</div> </div>
</p> </p>

@ -73,5 +73,7 @@ urlpatterns = [
path('admin/tournament-import/', views.tournament_import_view, name='tournament_import'), path('admin/tournament-import/', views.tournament_import_view, name='tournament_import'),
path('admin/tournament-import-tr/', views.tournament_import_team_reg, name='tournament_import'), path('admin/tournament-import-tr/', views.tournament_import_team_reg, name='tournament_import'),
path('admin/users-export/', views.UserListExportView.as_view(), name='users_export'), path('admin/users-export/', views.UserListExportView.as_view(), name='users_export'),
path('activation-success/', views.activation_success, name='activation_success'),
path('activation-failed/', views.activation_failed, name='activation_failed'),
] ]

@ -525,10 +525,16 @@ def activate(request, uidb64, token):
from django.contrib.auth import login from django.contrib.auth import login
login(request, user, backend='django.contrib.auth.backends.ModelBackend') login(request, user, backend='django.contrib.auth.backends.ModelBackend')
next_url = request.GET.get('next', '/') return redirect('activation_success')
return redirect(next_url)
else: else:
return HttpResponse('Le lien est invalide.') # Redirect to a custom error page
return redirect('activation_failed') # Define this URL in your urls.py
def activation_success(request):
return render(request, 'registration/activation_success.html')
def activation_failed(request):
return render(request, 'registration/activation_failed.html')
def club_broadcast(request, broadcast_code): def club_broadcast(request, broadcast_code):
club = get_object_or_404(Club, broadcast_code=broadcast_code) club = get_object_or_404(Club, broadcast_code=broadcast_code)

Loading…
Cancel
Save