improve registration

online_registration
Raz 12 months ago
parent da18a5d836
commit 97e62792bb
  1. 29
      tournaments/forms.py
  2. 33
      tournaments/templates/profile.html
  3. 10
      tournaments/templates/registration/my_tournaments.html
  4. 1
      tournaments/templates/tournaments/navigation_base.html
  5. 7
      tournaments/templates/tournaments/tournament_info.html
  6. 5
      tournaments/urls.py
  7. 185
      tournaments/views.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 django import forms
from .models import CustomUser from .models import CustomUser
import re # Import the re module for regular expressions import re # Import the re module for regular expressions
from .utils.licence_validator import LicenseValidator 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): class CustomUserCreationForm(UserCreationForm):
@ -116,14 +122,6 @@ class AddPlayerForm(forms.Form):
# Return the cleaned data with any modifications applied # Return the cleaned data with any modifications applied
return cleaned_data 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): class CustomPasswordResetForm(PasswordResetForm):
def save(self, *args, **kwargs): def save(self, *args, **kwargs):
""" """
@ -153,3 +151,16 @@ class CustomPasswordResetForm(PasswordResetForm):
# Send the email # Send the email
send_mail(subject, message, None, [user.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',
}

@ -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 %}
<div class="grid-x">
<div class="cell medium-6 large-6 topblock my-block">
<div class="bubble">
<label class="title">Mes informations</label>
<form method="post">
{% csrf_token %}
{{ form.as_p }}
<button type="submit" class="button">Sauver les changements</button>
</form>
</div>
<div class="cell medium-6 large-6 topblock my-block">
<div class="bubble">
<label class="title">Mot de passe</label>
<form method="post" action="{% url 'password_change' %}">
{% csrf_token %}
{{ password_change_form.as_p }}
<button type="submit" class="button">Modifier le mot de passe</button>
</form>
</div>
</div>
{% endblock %}

@ -1,6 +1,6 @@
{% extends 'tournaments/base.html' %} {% extends 'tournaments/base.html' %}
{% block head_title %} Mon Compte {% endblock %} {% block head_title %} Mes tournois {% endblock %}
{% block first_title %} Mon Compte Padel Club {% endblock %} {% block first_title %} Mes tournois Padel Club {% endblock %}
{% block second_title %} {{ user.first_name }} {{ user.last_name }} {% endblock %} {% block second_title %} {{ user.first_name }} {{ user.last_name }} {% endblock %}
{% block content %} {% block content %}
@ -12,8 +12,8 @@
<div class="grid-x"> <div class="grid-x">
<div class="cell medium-6 large-6 topblock my-block"> <div class="cell medium-6 large-6 topblock my-block">
<h1 class="club my-block">Vos tournois à venir</h1 >
<div class="bubble"> <div class="bubble">
<label class="title">Vos tournois à venir</label>
{% if upcoming_tournaments %} {% if upcoming_tournaments %}
{% for tournament in upcoming_tournaments %} {% for tournament in upcoming_tournaments %}
{% include 'tournaments/tournament_row.html' %} {% include 'tournaments/tournament_row.html' %}
@ -24,8 +24,8 @@
</div> </div>
</div> </div>
<div class="cell medium-6 large-6 topblock my-block"> <div class="cell medium-6 large-6 topblock my-block">
<h1 class="club my-block">Vos tournois en cours</h1 >
<div class="bubble"> <div class="bubble">
<label class="title">Vos tournois en cours</label>
{% if running_tournaments %} {% if running_tournaments %}
{% for tournament in running_tournaments %} {% for tournament in running_tournaments %}
{% include 'tournaments/tournament_row.html' %} {% include 'tournaments/tournament_row.html' %}
@ -37,8 +37,8 @@
</div> </div>
</div> </div>
<div class="cell medium-6 large-6 topblock my-block"> <div class="cell medium-6 large-6 topblock my-block">
<h1 class="club my-block">Vos tournois terminés</h1 >
<div class="bubble"> <div class="bubble">
<label class="title">Vos tournois terminés</label>
{% if ended_tournaments %} {% if ended_tournaments %}
{% for tournament in ended_tournaments %} {% for tournament in ended_tournaments %}
{% include 'tournaments/tournament_row.html' %} {% include 'tournaments/tournament_row.html' %}

@ -3,6 +3,7 @@
<a href="{% url 'index' %}">Accueil</a> <a href="{% url 'index' %}">Accueil</a>
<a href="{% url 'clubs' %}">Clubs</a> <a href="{% url 'clubs' %}">Clubs</a>
{% if user.is_authenticated %} {% if user.is_authenticated %}
<a href="{% url 'my-tournaments' %}">Mes tournois</a>
<a href="{% url 'profile' %}">Mon compte</a> <a href="{% url 'profile' %}">Mon compte</a>
<a href="{% url 'logout' %}">Se déconnecter</a> <a href="{% url 'logout' %}">Se déconnecter</a>
{% else %} {% else %}

@ -59,6 +59,13 @@
<div class="alert alert-{{ message.tags }}">{{ message }}</div> <div class="alert alert-{{ message.tags }}">{{ message }}</div>
{% endfor %} {% endfor %}
<p>
<div>
<a href="{% url 'login' %}?next={{ request.path }}" class="styled-link">Connectez-vous !</a>
</div>
</p>
<p> <p>
<div> <div>
Vous avez besoin d'un compte Padel Club pour pouvoir vous inscrire en ligne. Vous avez besoin d'un compte Padel Club pour pouvoir vous inscrire en ligne.

@ -43,11 +43,12 @@ urlpatterns = [
path('login/', auth_views.LoginView.as_view(), name='login'), path('login/', auth_views.LoginView.as_view(), name='login'),
path('logout/', auth_views.LogoutView.as_view(), name='logout'), path('logout/', auth_views.LogoutView.as_view(), name='logout'),
path('signup/', views.signup, name='signup'), # URL pattern for signup 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/<str:tournament_id>/register/', views.register_tournament, name='register_tournament'), path('tournaments/<str:tournament_id>/register/', views.register_tournament, name='register_tournament'),
path('tournaments/<str:tournament_id>/unregister/', views.unregister_tournament, name='unregister_tournament'), path('tournaments/<str:tournament_id>/unregister/', views.unregister_tournament, name='unregister_tournament'),
path('password_reset/', auth_views.PasswordResetView.as_view(), name='password_reset'), 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('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('reset/done/', auth_views.PasswordResetCompleteView.as_view(), name='password_reset_complete'),
path('profile/', views.ProfileUpdateView.as_view(), name='profile'),
] ]

@ -1,65 +1,73 @@
from django.shortcuts import render, get_object_or_404 # Standard library imports
from django.http import HttpResponse import os
from django.utils.encoding import force_str import csv
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
import json import json
import time
import asyncio import asyncio
import csv from datetime import date, datetime, timedelta
from api.tokens import account_activation_token
# Third-party imports
from qr_code.qrcode.utils import QRCodeOptions from qr_code.qrcode.utils import QRCodeOptions
from .utils.apns import send_push_notification
import os
from .forms import SimpleForm # Django imports
from django.core.mail import EmailMessage from django.shortcuts import render, redirect, get_object_or_404
from datetime import timedelta from django.http import HttpResponse, JsonResponse, Http404
from django.urls import reverse, reverse_lazy
from django.utils import timezone from django.utils import timezone
from django.shortcuts import render, redirect from django.utils.encoding import force_str, force_bytes
from django.contrib.auth.forms import UserCreationForm from django.utils.http import urlsafe_base64_encode, urlsafe_base64_decode
from django.contrib.auth import login from django.template import loader
from django.template.loader import render_to_string
from django.urls import reverse
from django.contrib import messages 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.contrib.sites.shortcuts import get_current_site
from django.template.loader import render_to_string from django.contrib.auth import login
from django.utils.http import urlsafe_base64_encode, urlsafe_base64_decode from django.contrib.auth.decorators import login_required
from django.utils.encoding import force_bytes from django.contrib.auth.forms import (
UserCreationForm,
from django.contrib.auth.forms import SetPasswordForm SetPasswordForm,
)
from django.contrib.auth.views import PasswordResetConfirmView 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.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): def index(request):
@ -582,30 +590,7 @@ def profile(request):
# Assuming the authenticated user has a `licence_id` attribute # Assuming the authenticated user has a `licence_id` attribute
user_licence_id = request.user.licence_id 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', { return render(request, 'registration/profile.html', {
'tournaments': tournaments,
'upcoming_tournaments': upcoming_tournaments,
'running_tournaments': running_tournaments,
'ended_tournaments': ended_tournaments,
'user_name': user.username 'user_name': user.username
}) })
@ -880,3 +865,53 @@ class CustomPasswordResetConfirmView(PasswordResetConfirmView):
return user return user
except (TypeError, ValueError, User.DoesNotExist): except (TypeError, ValueError, User.DoesNotExist):
raise Http404("User not found") 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

Loading…
Cancel
Save