diff --git a/tournaments/forms.py b/tournaments/forms.py index adc0063..5b1244a 100644 --- a/tournaments/forms.py +++ b/tournaments/forms.py @@ -1,8 +1,14 @@ -from django.contrib.auth.forms import UserCreationForm, UserChangeForm +from django.contrib.auth.forms import UserCreationForm, UserChangeForm, PasswordResetForm from django import forms from .models import CustomUser import re # Import the re module for regular expressions from .utils.licence_validator import LicenseValidator +from django.core.mail import send_mail +from django.template.loader import render_to_string +from django.utils.http import urlsafe_base64_encode, urlsafe_base64_decode +from django.contrib.auth.tokens import default_token_generator +from django.contrib.sites.shortcuts import get_current_site +from django.utils.encoding import force_bytes class CustomUserCreationForm(UserCreationForm): @@ -116,14 +122,6 @@ class AddPlayerForm(forms.Form): # Return the cleaned data with any modifications applied return cleaned_data -from django.contrib.auth.forms import PasswordResetForm -from django.core.mail import send_mail -from django.template.loader import render_to_string -from django.utils.http import urlsafe_base64_encode, urlsafe_base64_decode -from django.contrib.auth.tokens import default_token_generator -from django.contrib.sites.shortcuts import get_current_site -from django.utils.encoding import force_bytes - class CustomPasswordResetForm(PasswordResetForm): def save(self, *args, **kwargs): """ @@ -153,3 +151,16 @@ class CustomPasswordResetForm(PasswordResetForm): # Send the email send_mail(subject, message, None, [user.email]) + +class ProfileUpdateForm(forms.ModelForm): + class Meta: + model = CustomUser + fields = ['first_name', 'last_name', 'licence_id', 'username', 'email', 'phone'] + labels = { + 'username': 'Nom d’utilisateur', + 'email': 'E-mail', + 'phone': 'Numéro de téléphone', + 'first_name': 'Prénom', + 'last_name': 'Nom de famille', + 'licence_id': 'Numéro de licence', + } diff --git a/tournaments/templates/profile.html b/tournaments/templates/profile.html new file mode 100644 index 0000000..ffde179 --- /dev/null +++ b/tournaments/templates/profile.html @@ -0,0 +1,33 @@ +{% extends 'tournaments/base.html' %} +{% block head_title %} Mon Compte {% endblock %} +{% block first_title %} Mon Compte Padel Club {% endblock %} +{% block second_title %} {{ user.first_name }} {{ user.last_name }} {% endblock %} + +{% block content %} + +{% include 'tournaments/navigation_base.html' %} + +{% load static %} +{% load tz %} + +
+
+
+ +
+ {% csrf_token %} + {{ form.as_p }} + +
+
+
+
+ +
+ {% csrf_token %} + {{ password_change_form.as_p }} + +
+
+
+{% endblock %} diff --git a/tournaments/templates/registration/profile.html b/tournaments/templates/registration/my_tournaments.html similarity index 82% rename from tournaments/templates/registration/profile.html rename to tournaments/templates/registration/my_tournaments.html index 5dbe9d5..cdb1c55 100644 --- a/tournaments/templates/registration/profile.html +++ b/tournaments/templates/registration/my_tournaments.html @@ -1,6 +1,6 @@ {% extends 'tournaments/base.html' %} -{% block head_title %} Mon Compte {% endblock %} -{% block first_title %} Mon Compte Padel Club {% endblock %} +{% block head_title %} Mes tournois {% endblock %} +{% block first_title %} Mes tournois Padel Club {% endblock %} {% block second_title %} {{ user.first_name }} {{ user.last_name }} {% endblock %} {% block content %} @@ -12,8 +12,8 @@
-

Vos tournois à venir

+ {% if upcoming_tournaments %} {% for tournament in upcoming_tournaments %} {% include 'tournaments/tournament_row.html' %} @@ -24,8 +24,8 @@
-

Vos tournois en cours

+ {% if running_tournaments %} {% for tournament in running_tournaments %} {% include 'tournaments/tournament_row.html' %} @@ -37,8 +37,8 @@
-

Vos tournois terminés

+ {% 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