diff --git a/tournaments/templates/registration/my_tournaments.html b/tournaments/templates/registration/my_tournaments.html index eee8c04..b118788 100644 --- a/tournaments/templates/registration/my_tournaments.html +++ b/tournaments/templates/registration/my_tournaments.html @@ -13,25 +13,35 @@
- +
+ +
+ {% if running_tournaments %} - {% for tournament in running_tournaments %} - {% include 'tournaments/tournament_row.html' %} - {% endfor %} + {% for tournament in running_tournaments %} + {% include 'tournaments/tournament_row.html' %} + {% endfor %} {% else %} - Aucun tournoi en cours +
+ Aucun tournoi en cours +
{% endif %}
- +
+ +
+ {% if upcoming_tournaments %} - {% for tournament in upcoming_tournaments %} - {% include 'tournaments/tournament_row.html' %} - {% endfor %} + {% for tournament in upcoming_tournaments %} + {% include 'tournaments/tournament_row.html' %} + {% endfor %} {% else %} - Aucun tournoi à venir +
+ Aucun tournoi à venir +
{% endif %}
@@ -39,13 +49,26 @@
- + +
+ +
+ {% if ended_tournaments %} - {% for tournament in ended_tournaments %} - {% include 'tournaments/tournament_row.html' %} - {% endfor %} + {% for tournament in ended_tournaments %} + {% include 'tournaments/tournament_row.html' %} + {% endfor %} + {% else %} - Aucun tournoi terminé +
+ Aucun tournoi terminé +
{% endif %}
diff --git a/tournaments/urls.py b/tournaments/urls.py index e0a49bb..8019c74 100644 --- a/tournaments/urls.py +++ b/tournaments/urls.py @@ -60,6 +60,7 @@ urlpatterns = [ path('signup/', views.signup, name='signup'), # URL pattern for signup # path('profile/', views.profile, name='profile'), # URL pattern for signup path('my-tournaments/', views.my_tournaments, name='my-tournaments'), # URL pattern for signup + path('all_my_ended_tournaments/', views.all_my_ended_tournaments, name='all-my-ended-tournaments'), # URL pattern for signup path('tournaments//register/', views.register_tournament, name='register_tournament'), path('tournaments//unregister/', views.unregister_tournament, name='unregister_tournament'), path('password_reset/', auth_views.PasswordResetView.as_view(), name='password_reset'), diff --git a/tournaments/views.py b/tournaments/views.py index 14990c6..2c7c2e0 100644 --- a/tournaments/views.py +++ b/tournaments/views.py @@ -903,10 +903,40 @@ def my_tournaments(request): return render(request, 'registration/my_tournaments.html', { 'upcoming_tournaments': upcoming_tournaments, 'running_tournaments': running_tournaments, - 'ended_tournaments': ended_tournaments, + 'ended_tournaments': ended_tournaments[:12], 'user_name': user.username }) +@login_required +def all_my_ended_tournaments(request): + user_licence_id = request.user.licence_id + + # If no licence_id, return empty lists + if user_licence_id is None: + return render(request, '/tournaments.html', { + 'tournaments': [], + 'title': "Palmarès", + }) + + # Get all tournaments for the user based on their licence + validator = LicenseValidator(user_licence_id) + stripped_license = validator.stripped_license + + def filter_user_tournaments(tournaments): + return [t for t in tournaments if t.team_registrations.filter( + player_registrations__licence_id__icontains=stripped_license, + walk_out=False + ).exists()] + + ended_tournaments = filter_user_tournaments(finished_tournaments(None)) + + return render(request, + "tournaments/tournaments_list.html", + { + 'tournaments': ended_tournaments, + 'title': "Palmarès", + }) + from django.contrib.auth.mixins import LoginRequiredMixin class ProfileUpdateView(LoginRequiredMixin, UpdateView):