+
{% if ended_tournaments %}
{% for tournament in ended_tournaments %}
{% include 'tournaments/tournament_row.html' %}
diff --git a/tournaments/templates/tournaments/navigation_base.html b/tournaments/templates/tournaments/navigation_base.html
index 7f12a87..d895f8a 100644
--- a/tournaments/templates/tournaments/navigation_base.html
+++ b/tournaments/templates/tournaments/navigation_base.html
@@ -3,6 +3,7 @@
Accueil
Clubs
{% if user.is_authenticated %}
+
Mes tournois
Mon compte
Se déconnecter
{% else %}
diff --git a/tournaments/templates/tournaments/tournament_info.html b/tournaments/templates/tournaments/tournament_info.html
index abde129..ab8b2f2 100644
--- a/tournaments/templates/tournaments/tournament_info.html
+++ b/tournaments/templates/tournaments/tournament_info.html
@@ -59,6 +59,13 @@
{{ message }}
{% endfor %}
+
+
+
+
+
Vous avez besoin d'un compte Padel Club pour pouvoir vous inscrire en ligne.
diff --git a/tournaments/urls.py b/tournaments/urls.py
index 6afde58..2f77f26 100644
--- a/tournaments/urls.py
+++ b/tournaments/urls.py
@@ -43,11 +43,12 @@ urlpatterns = [
path('login/', auth_views.LoginView.as_view(), name='login'),
path('logout/', auth_views.LogoutView.as_view(), name='logout'),
path('signup/', views.signup, name='signup'), # URL pattern for signup
- path('profile/', views.profile, name='profile'), # 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('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'),
path('password_reset_done/', auth_views.PasswordResetDoneView.as_view(), name='password_reset_done'),
path('reset/done/', auth_views.PasswordResetCompleteView.as_view(), name='password_reset_complete'),
-
+ path('profile/', views.ProfileUpdateView.as_view(), name='profile'),
]
diff --git a/tournaments/views.py b/tournaments/views.py
index bdc47fe..e1beefa 100644
--- a/tournaments/views.py
+++ b/tournaments/views.py
@@ -1,65 +1,73 @@
-from django.shortcuts import render, get_object_or_404
-from django.http import HttpResponse
-from django.utils.encoding import force_str
-from django.utils.http import urlsafe_base64_encode, urlsafe_base64_decode
-from django.urls import reverse
-
-from django.views.decorators.csrf import csrf_exempt
-from django.core.files.storage import default_storage
-from django.core.files.base import ContentFile
-
-from tournaments.models.device_token import DeviceToken
-from tournaments.models.player_enums import PlayerDataSource, PlayerSexType
-
-from .models import Court, DateInterval, Club, Tournament, CustomUser, Event, Round, GroupStage, Match, TeamScore, TeamRegistration, PlayerRegistration, Purchase, FailedApiCall
-from .models import TeamSummon, FederalCategory
-from datetime import datetime, timedelta
-import time
-
-from django.template import loader
-from datetime import date
-from django.http import JsonResponse, HttpResponse
-from django.db.models import Q
+# Standard library imports
+import os
+import csv
import json
+import time
import asyncio
-import csv
-
-from api.tokens import account_activation_token
+from datetime import date, datetime, timedelta
+# Third-party imports
from qr_code.qrcode.utils import QRCodeOptions
-from .utils.apns import send_push_notification
-import os
-from .forms import SimpleForm
-from django.core.mail import EmailMessage
-from datetime import timedelta
+# Django imports
+from django.shortcuts import render, redirect, get_object_or_404
+from django.http import HttpResponse, JsonResponse, Http404
+from django.urls import reverse, reverse_lazy
from django.utils import timezone
-from django.shortcuts import render, redirect
-from django.contrib.auth.forms import UserCreationForm
-from django.contrib.auth import login
-
-from django.urls import reverse
+from django.utils.encoding import force_str, force_bytes
+from django.utils.http import urlsafe_base64_encode, urlsafe_base64_decode
+from django.template import loader
+from django.template.loader import render_to_string
from django.contrib import messages
-from .forms import TournamentRegistrationForm, AddPlayerForm
-
-from .utils.licence_validator import LicenseValidator
-from .utils.player_search import get_player_name_from_csv
-
-from django.contrib.auth.decorators import login_required
-from .forms import SimpleCustomUserCreationForm
from django.contrib.sites.shortcuts import get_current_site
-from django.template.loader import render_to_string
-from django.utils.http import urlsafe_base64_encode, urlsafe_base64_decode
-from django.utils.encoding import force_bytes
-
-from django.contrib.auth.forms import SetPasswordForm
+from django.contrib.auth import login
+from django.contrib.auth.decorators import login_required
+from django.contrib.auth.forms import (
+ UserCreationForm,
+ SetPasswordForm,
+)
from django.contrib.auth.views import PasswordResetConfirmView
-from django.urls import reverse_lazy
-from django.shortcuts import render
-from django.utils.http import urlsafe_base64_decode
-from django.contrib.auth.tokens import default_token_generator
from django.contrib.auth.models import User
-from django.http import Http404
+from django.contrib.auth.tokens import default_token_generator
+from django.db.models import Q
+from django.views.decorators.csrf import csrf_exempt
+from django.core.files.storage import default_storage
+from django.core.files.base import ContentFile
+from django.core.mail import EmailMessage
+
+# Local application imports
+from .models import (
+ Court,
+ DateInterval,
+ Club,
+ Tournament,
+ CustomUser,
+ Event,
+ Round,
+ GroupStage,
+ Match,
+ TeamScore,
+ TeamRegistration,
+ PlayerRegistration,
+ Purchase,
+ FailedApiCall,
+ TeamSummon,
+ FederalCategory,
+)
+from .forms import (
+ SimpleForm,
+ SimpleCustomUserCreationForm,
+ TournamentRegistrationForm,
+ AddPlayerForm,
+ ProfileUpdateForm,
+)
+from .utils.apns import send_push_notification
+from .utils.licence_validator import LicenseValidator
+from .utils.player_search import get_player_name_from_csv
+from api.tokens import account_activation_token
+from tournaments.models.device_token import DeviceToken
+from tournaments.models.player_enums import PlayerDataSource, PlayerSexType
+from django.views.generic.edit import UpdateView
def index(request):
@@ -582,30 +590,7 @@ def profile(request):
# 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')
-
- # Current time
- current_time = timezone.now()
-
- # Separate tournaments into categories
- upcoming_tournaments = tournaments.filter(start_date__gt=current_time)
- running_tournaments = tournaments.filter(start_date__lte=current_time, end_date=None)
- ended_tournaments = tournaments.filter(end_date__isnull=False)
-
return render(request, 'registration/profile.html', {
- 'tournaments': tournaments,
- 'upcoming_tournaments': upcoming_tournaments,
- 'running_tournaments': running_tournaments,
- 'ended_tournaments': ended_tournaments,
'user_name': user.username
})
@@ -880,3 +865,53 @@ class CustomPasswordResetConfirmView(PasswordResetConfirmView):
return user
except (TypeError, ValueError, User.DoesNotExist):
raise Http404("User not found")
+
+@login_required
+def my_tournaments(request):
+ user = request.user # Get the currently authenticated user
+
+ # 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')
+
+ # Current time
+ current_time = timezone.now()
+
+ # Separate tournaments into categories
+ upcoming_tournaments = tournaments.filter(start_date__gt=current_time)
+ running_tournaments = tournaments.filter(start_date__lte=current_time, end_date=None)
+ ended_tournaments = tournaments.filter(end_date__isnull=False)
+
+ return render(request, 'registration/my_tournaments.html', {
+ 'tournaments': tournaments,
+ 'upcoming_tournaments': upcoming_tournaments,
+ 'running_tournaments': running_tournaments,
+ 'ended_tournaments': ended_tournaments,
+ 'user_name': user.username
+ })
+
+from django.contrib.auth.forms import PasswordChangeForm
+
+class ProfileUpdateView(UpdateView):
+ model = CustomUser
+ form_class = ProfileUpdateForm
+ template_name = 'profile.html'
+ success_url = reverse_lazy('profile')
+
+ def get_object(self, queryset=None):
+ return self.request.user
+
+ def get_context_data(self, **kwargs):
+ context = super().get_context_data(**kwargs)
+ context['password_change_form'] = PasswordChangeForm(user=self.request.user)
+ return context