From 64eba2a96536eb11adf60cc6e7d0fb0348b62a75 Mon Sep 17 00:00:00 2001
From: Raz
Date: Fri, 15 Nov 2024 08:49:45 +0100
Subject: [PATCH] clean up info view
---
tournaments/models/team_registration.py | 8 +++-
.../tournaments/tournament_info.html | 35 +++++++++++------
tournaments/views.py | 39 ++++++++++++++-----
3 files changed, 59 insertions(+), 23 deletions(-)
diff --git a/tournaments/models/team_registration.py b/tournaments/models/team_registration.py
index 709c61f..78da28b 100644
--- a/tournaments/models/team_registration.py
+++ b/tournaments/models/team_registration.py
@@ -37,11 +37,15 @@ class TeamRegistration(models.Model):
# return f"{self.name}: {self.player_names()}"
return self.player_names()
+ def player_names_as_list(self):
+ return [pr.name() for pr in self.playerregistration_set.all()]
+
+
def team_names(self):
if self.name:
return [self.name]
else:
- return [pr.name() for pr in self.playerregistration_set.all()]
+ return self.player_names_as_list()
def shortened_team_names(self):
if self.name:
@@ -54,7 +58,7 @@ class TeamRegistration(models.Model):
return [pr.shortened_name() for pr in players]
def player_names(self):
- names = [pr.name() for pr in self.playerregistration_set.all()]
+ names = self.player_names_as_list()
str = " - ".join(names)
if len(str) > 0:
return str
diff --git a/tournaments/templates/tournaments/tournament_info.html b/tournaments/templates/tournaments/tournament_info.html
index 3f36fb8..b36206a 100644
--- a/tournaments/templates/tournaments/tournament_info.html
+++ b/tournaments/templates/tournaments/tournament_info.html
@@ -37,21 +37,34 @@
{{ tournament.event.creator.full_name }}
{% endif %}
+
- {% if tournament.online_register_is_enabled %}
- {% if is_registered %}
-
- Unregister from Tournament
-
- {% else %}
-
- Register for Tournament
-
- {% endif %}
+ {% if tournament.online_register_is_enabled %}
+ Votre équipe
+
+
+ {% if team %}
+
+
+ {% for name in team.player_names_as_list %}
+
{{ name }}
+ {% endfor %}
+
+
+
+
Inscrit le {{ team.registration_date }}
+
+
+ Se désinscrire
+
+ {% else %}
+
+ S'inscrire
+
{% endif %}
+ {% endif %}
-
{% endblock %}
diff --git a/tournaments/views.py b/tournaments/views.py
index 4bb728a..1c52aea 100644
--- a/tournaments/views.py
+++ b/tournaments/views.py
@@ -102,20 +102,28 @@ def future_tournaments(club_id):
def tournament_info(request, tournament_id):
tournament = get_object_or_404(Tournament, pk=tournament_id)
- is_registered = False
+ registered_user = None
+ team_registration = None
if request.user.is_authenticated:
- # Assuming user's licence_id is stored in the user profile (e.g., request.user.profile.licence_id)
+ # Assuming user's licence_id is stored in the user profile (e.g., request.user.licence_id)
user_licence_id = request.user.licence_id
- # Check if there is a PlayerRegistration for this user in this tournament
- is_registered = PlayerRegistration.objects.filter(
- licence_id__startswith=user_licence_id,
- team_registration__tournament=tournament
- ).exists()
+ if user_licence_id is not None:
+ validator = LicenseValidator(user_licence_id)
+ stripped_license = validator.stripped_license
+ # Check if there is a PlayerRegistration for this user in this tournament
+ registered_user = PlayerRegistration.objects.filter(
+ licence_id__startswith=stripped_license,
+ team_registration__tournament=tournament
+ ).first()
+
+ # If the user is registered, retrieve their team registration
+ if registered_user:
+ team_registration = registered_user.team_registration
return render(request, 'tournaments/tournament_info.html', {
'tournament': tournament,
- 'is_registered': is_registered,
+ 'team': team_registration,
})
@@ -552,8 +560,19 @@ def send_verification_email(request, user):
def profile(request):
user = request.user # Get the currently authenticated user
- # Query tournaments where the user is registered
- tournaments = Tournament.objects.all()
+ # Assuming the authenticated user has a `licence_id` attribute
+ user_licence_id = request.user.licence_id
+
+ # Check if licence_id is None
+ if user_licence_id is None:
+ tournaments = Tournament.objects.none() # Return an empty queryset
+ else:
+ validator = LicenseValidator(user_licence_id)
+ stripped_license = validator.stripped_license
+ # Filter tournaments where the authenticated user's licence_id starts with the given value
+ tournaments = Tournament.objects.filter(
+ teamregistration__playerregistration__licence_id__startswith=stripped_license
+ ).distinct().order_by('-start_date')
return render(request, 'registration/profile.html', {
'tournaments': tournaments,