diff --git a/tournaments/forms.py b/tournaments/forms.py
index 49895d9..34d2a36 100644
--- a/tournaments/forms.py
+++ b/tournaments/forms.py
@@ -96,6 +96,16 @@ class AddPlayerForm(forms.Form):
self.cleaned_data['last_name'] = last_name
return last_name
+ def clean_first_name(self):
+ first_name = self.cleaned_data.get('first_name')
+
+ # Convert to capitalize
+ first_name = first_name.capitalize()
+
+ # Update the cleaned_data with the modified licence_id
+ self.cleaned_data['first_name'] = first_name
+ return first_name
+
def clean(self):
cleaned_data = super().clean()
diff --git a/tournaments/static/tournaments/css/style.css b/tournaments/static/tournaments/css/style.css
index 202669b..51e96dd 100644
--- a/tournaments/static/tournaments/css/style.css
+++ b/tournaments/static/tournaments/css/style.css
@@ -689,3 +689,14 @@ h-margin {
.right-content {
margin-left: auto;
}
+
+.styled-link {
+ text-decoration: underline; /* Ensures the link is underlined */
+ color: #f39200; /* Use your main color variable if defined */
+ font-weight: bold; /* Optional: To make the link more prominent */
+}
+
+.styled-link:hover {
+ color: #f39200; /* Optional: Define a hover color */
+ text-decoration: none; /* Optional: Remove underline on hover */
+}
diff --git a/tournaments/templates/register_tournament.html b/tournaments/templates/register_tournament.html
index af45377..fd477dc 100644
--- a/tournaments/templates/register_tournament.html
+++ b/tournaments/templates/register_tournament.html
@@ -54,17 +54,34 @@
{% if current_players|length < 2 %}
+
+ {% if user_without_licence %}
+
+ Une licence est obligatoire pour vous inscrire :
+
+ {% endif %}
+
{{ add_player_form.licence_id.label_tag }}
{{ add_player_form.licence_id }}
- {% if add_player_form.first_tournament %}
- Précisez les informations du joueur :
+ {% if add_player_form.first_tournament or user_without_licence %}
+ {% if not user_without_licence %}
+
+ Vous avez besoin d'un compte Padel Club pour pouvoir vous inscrire en ligne.
+ Créer le tout de suite !
+
+
+ {% endif %}
+
+
+
{% endif %}
diff --git a/tournaments/views.py b/tournaments/views.py
index 7ddf151..490ed09 100644
--- a/tournaments/views.py
+++ b/tournaments/views.py
@@ -358,7 +358,8 @@ def activate(request, uidb64, token):
user.is_active = True
user.save()
login(request, user)
- return redirect('index') # Redirect to the homepage or any other page you prefer
+ next_url = request.GET.get('next', '/')
+ return redirect(next_url)
else:
return HttpResponse('Le lien est invalide.')
@@ -529,6 +530,9 @@ def send_email(mail, name):
@csrf_exempt
def signup(request):
+ next_url = request.GET.get('next', '/') # Get the 'next' parameter from the request
+ print('next_url', next_url)
+
if request.method == 'POST':
form = SimpleCustomUserCreationForm(request.POST)
if form.is_valid():
@@ -537,26 +541,28 @@ def signup(request):
user.save()
# Send verification email
- send_verification_email(request, user)
- request.session['pre_login_username'] = user.username
- request.session['pre_login_password'] = user.password # Store hashed password, or handle with caution
+ send_verification_email(request, user, next_url)
messages.success(request, "Votre compte a été créé ! Veuillez vérifier votre e-mail pour confirmer votre compte.")
- return redirect('login') # Redirect to login page or a custom message page
+ return redirect(next_url) # Redirect directly to the 'next' URL
else:
form = SimpleCustomUserCreationForm()
return render(request, 'registration/signup.html', {'form': form})
-def send_verification_email(request, user):
+def send_verification_email(request, user, next_url):
+ print('next_url', next_url)
current_site = get_current_site(request)
mail_subject = 'Activez votre compte Padel Club !'
+ # Prepare the email subject and message
message = render_to_string('tournaments/acc_active_email.html', {
'user': user,
'domain': current_site.domain,
'uid': urlsafe_base64_encode(force_bytes(user.pk)),
'token': account_activation_token.make_token(user),
+ 'next': next_url, # Pass next URL to the template
})
+
email = EmailMessage(mail_subject, message, to=[user.email])
email.send()
@@ -599,21 +605,23 @@ def register_tournament(request, tournament_id):
registration_successful = False # Flag for registration status
team_form = None
add_player_form = None
+ if 'user_without_licence' not in request.session:
+ request.session['user_without_licence'] = False
+
+ user_without_licence = request.session['user_without_licence']
# Process forms
if request.method == 'POST':
team_form = TournamentRegistrationForm(request.POST)
- add_player_form = AddPlayerForm(request.POST)
# Check if the add player form is submitted
+ add_player_form = AddPlayerForm(request.POST)
if 'add_player' in request.POST and add_player_form.is_valid():
player_data = add_player_form.cleaned_data
-
# Validate the license ID before adding the player
licence_id = player_data['licence_id'].upper()
# Instantiate your custom validator and validate the license ID
validator = LicenseValidator(licence_id)
-
if validator.validate_license() is False:
messages.error(request, f"Le numéro de licence est invalide, la lettre ne correspond pas. {validator.computed_license_key}")
return render(request, 'register_tournament.html', {
@@ -622,34 +630,43 @@ def register_tournament(request, tournament_id):
'tournament': tournament,
'registration_successful': registration_successful,
'current_players': request.session['team_registration'],
+ 'user_without_licence': user_without_licence
})
# Check if the player with the same licence_id already exists in the session
existing_players = [player['licence_id'] for player in request.session['team_registration']]
if licence_id in existing_players:
- messages.error(request, 'This player is already added to the team.')
+ messages.error(request, "Ce joueur est déjà dans l'équipe.")
return render(request, 'register_tournament.html', {
'team_form': team_form,
'add_player_form': add_player_form,
'tournament': tournament,
'registration_successful': registration_successful,
'current_players': request.session['team_registration'],
+ 'user_without_licence': user_without_licence
})
else:
# Check if a PlayerRegistration with the same licence_id already exists in the database
stripped_license = validator.stripped_license
if validate_license_id(stripped_license, tournament):
- messages.error(request, 'A player with this licence ID is already registered in a team.')
+ messages.error(request, "Un joueur avec ce numéro de licence est déjà inscrit dans une équipe.")
return render(request, 'register_tournament.html', {
'team_form': team_form,
'add_player_form': add_player_form,
'tournament': tournament,
'registration_successful': registration_successful,
'current_players': request.session['team_registration'],
+ 'user_without_licence': user_without_licence
})
elif add_player_form.names_is_valid():
+ add_player_form = AddPlayerForm()
request.session['team_registration'].append(player_data)
+ if request.user.licence_id is None:
+ request.session['user_without_licence'] = False
+ request.user.licence_id = validator.computed_licence_id
+ request.user.save()
request.session.modified = True # Ensure session is updated
+
else:
if add_player_form.first_tournament is False:
# Retrieve player names from the CSV file
@@ -661,6 +678,7 @@ def register_tournament(request, tournament_id):
# If validation passes, add the player to the session without clearing previous ones
request.session['team_registration'].append(player_data)
request.session.modified = True # Ensure session is updated
+ add_player_form = AddPlayerForm()
else:
add_player_form.first_tournament = True
@@ -702,43 +720,57 @@ def register_tournament(request, tournament_id):
request.session['team_registration'] = []
registration_successful = True
else:
+ add_player_form = AddPlayerForm()
+
request.session['team_registration'] = []
+ user_licence_id = request.user.licence_id
initial_data = {}
+ player_data = {}
+
# Add the authenticated user to the session as the first player if not already added
if request.user.is_authenticated:
initial_data = {
'email': request.user.email,
'phone': request.user.phone,
}
- existing_players = [player['licence_id'] for player in request.session['team_registration']]
- if request.user.licence_id not in existing_players:
- # Add the authenticated user as the first player in the session
+
+ if user_licence_id is not None:
+ validator = LicenseValidator(user_licence_id)
+ existing_players = [player['licence_id'] for player in request.session['team_registration']]
+ if user_licence_id not in existing_players:
+ # Add the authenticated user as the first player in the session
+ player_data = {
+ 'first_name': request.user.first_name,
+ 'last_name': request.user.last_name.upper(),
+ 'email': request.user.email,
+ 'phone': request.user.phone,
+ 'licence_id': validator.computed_licence_id
+ }
+
+ first_name, last_name, rank = get_player_name_from_csv(user_licence_id)
+ if first_name and last_name and rank:
+ player_data['rank'] = rank
+
+ request.session['team_registration'].insert(0, player_data) # Add them as the first player
+ request.session.modified = True # Ensure session is updated
+ else:
player_data = {
'first_name': request.user.first_name,
'last_name': request.user.last_name.upper(),
- 'email': request.user.email,
- 'phone': request.user.phone,
- 'licence_id': request.user.licence_id,
}
-
- first_name, last_name, rank = get_player_name_from_csv(request.user.licence_id)
- if first_name and last_name and rank:
- validator = LicenseValidator(request.user.licence_id)
- player_data['licence_id'] = validator.computed_licence_id
- player_data['rank'] = rank
-
- request.session['team_registration'].insert(0, player_data) # Add them as the first player
+ add_player_form = AddPlayerForm(initial=player_data)
+ request.session['user_without_licence'] = True
request.session.modified = True # Ensure session is updated
+ user_without_licence = True
team_form = TournamentRegistrationForm(initial=initial_data)
- add_player_form = AddPlayerForm()
-
return render(request, 'register_tournament.html', {
'team_form': team_form,
'add_player_form': add_player_form,
'tournament': tournament,
'registration_successful': registration_successful,
'current_players': request.session['team_registration'],
+ 'user_without_licence': request.session['user_without_licence']
})