clean up info view

online_registration
Raz 12 months ago
parent 3066f184f6
commit 64eba2a965
  1. 8
      tournaments/models/team_registration.py
  2. 21
      tournaments/templates/tournaments/tournament_info.html
  3. 35
      tournaments/views.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

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

@ -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
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
is_registered = PlayerRegistration.objects.filter(
licence_id__startswith=user_licence_id,
registered_user = PlayerRegistration.objects.filter(
licence_id__startswith=stripped_license,
team_registration__tournament=tournament
).exists()
).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,

Loading…
Cancel
Save