clean up info view

online_registration
Raz 12 months ago
parent 3066f184f6
commit 64eba2a965
  1. 8
      tournaments/models/team_registration.py
  2. 35
      tournaments/templates/tournaments/tournament_info.html
  3. 39
      tournaments/views.py

@ -37,11 +37,15 @@ class TeamRegistration(models.Model):
# return f"{self.name}: {self.player_names()}" # return f"{self.name}: {self.player_names()}"
return 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): def team_names(self):
if self.name: if self.name:
return [self.name] return [self.name]
else: else:
return [pr.name() for pr in self.playerregistration_set.all()] return self.player_names_as_list()
def shortened_team_names(self): def shortened_team_names(self):
if self.name: if self.name:
@ -54,7 +58,7 @@ class TeamRegistration(models.Model):
return [pr.shortened_name() for pr in players] return [pr.shortened_name() for pr in players]
def player_names(self): def player_names(self):
names = [pr.name() for pr in self.playerregistration_set.all()] names = self.player_names_as_list()
str = " - ".join(names) str = " - ".join(names)
if len(str) > 0: if len(str) > 0:
return str return str

@ -37,21 +37,34 @@
<div>{{ tournament.event.creator.full_name }}</div> <div>{{ tournament.event.creator.full_name }}</div>
</p> </p>
{% endif %} {% endif %}
</div>
{% if tournament.online_register_is_enabled %} {% if tournament.online_register_is_enabled %}
{% if is_registered %} <h1 class="club my-block topmargin20">Votre équipe</h1 >
<p>
<a href="{% url 'unregister_tournament' tournament.id %}" class="button danger">Unregister from Tournament</a> <div class="bubble">
</p> {% if team %}
{% else %} <p>
<p> <div class="semibold">
<a href="{% url 'register_tournament' tournament.id %}?reset=true" class="button">Register for Tournament</a> {% for name in team.player_names_as_list %}
</p> <div>{{ name }}</div>
{% endif %} {% endfor %}
</div>
</p>
<p>
<div>Inscrit le {{ team.registration_date }}</div>
</p>
<p>
<a href="{% url 'unregister_tournament' tournament.id %}" class="button danger">Se désinscrire</a>
</p>
{% else %}
<p>
<a href="{% url 'register_tournament' tournament.id %}?reset=true" class="button">S'inscrire</a>
</p>
{% endif %} {% endif %}
{% endif %}
</div> </div>
</div> </div>
</div> </div>
{% endblock %} {% endblock %}

@ -102,20 +102,28 @@ def future_tournaments(club_id):
def tournament_info(request, tournament_id): def tournament_info(request, tournament_id):
tournament = get_object_or_404(Tournament, pk=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: 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 user_licence_id = request.user.licence_id
# Check if there is a PlayerRegistration for this user in this tournament if user_licence_id is not None:
is_registered = PlayerRegistration.objects.filter( validator = LicenseValidator(user_licence_id)
licence_id__startswith=user_licence_id, stripped_license = validator.stripped_license
team_registration__tournament=tournament # Check if there is a PlayerRegistration for this user in this tournament
).exists() 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', { return render(request, 'tournaments/tournament_info.html', {
'tournament': tournament, 'tournament': tournament,
'is_registered': is_registered, 'team': team_registration,
}) })
@ -552,8 +560,19 @@ def send_verification_email(request, user):
def profile(request): def profile(request):
user = request.user # Get the currently authenticated user user = request.user # Get the currently authenticated user
# Query tournaments where the user is registered # Assuming the authenticated user has a `licence_id` attribute
tournaments = Tournament.objects.all() 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', { return render(request, 'registration/profile.html', {
'tournaments': tournaments, 'tournaments': tournaments,

Loading…
Cancel
Save