- {% if user_without_licence %}
+ {% if user_without_licence and tournament.license_is_required %}
Une licence est obligatoire pour vous inscrire :
{% endif %}
+ {% if tournament.license_is_required %}
{{ add_player_form.licence_id.label_tag }}
{{ add_player_form.licence_id }}
- {% if add_player_form.first_tournament or user_without_licence %}
- {% if not user_without_licence %}
+ {% endif %}
+ {% if add_player_form.first_tournament or user_without_licence or tournament.license_is_required is False %}
+ {% if not user_without_licence and tournament.license_is_required is True %}
- {% if user.is_authenticated and user.is_active %}
+ {% if tournament.account_is_required is False or user.is_authenticated and user.is_active %}
diff --git a/tournaments/views.py b/tournaments/views.py
index e1beefa..63a5476 100644
--- a/tournaments/views.py
+++ b/tournaments/views.py
@@ -613,10 +613,10 @@ def register_tournament(request, tournament_id):
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:
+ if validator.validate_license() is False and tournament.license_is_required is True:
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', {
'team_form': team_form,
@@ -629,7 +629,7 @@ def register_tournament(request, tournament_id):
# 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:
+ if validator.validate_license() and licence_id in existing_players:
messages.error(request, "Ce joueur est déjà dans l'équipe.")
return render(request, 'register_tournament.html', {
'team_form': team_form,
@@ -642,7 +642,7 @@ def register_tournament(request, tournament_id):
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):
+ if validator.validate_license() and validate_license_id(stripped_license, tournament) and tournament.license_is_required is True:
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,
@@ -655,7 +655,7 @@ def register_tournament(request, tournament_id):
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:
+ if request.user.is_authenticated and request.user.licence_id is None:
request.session['user_without_licence'] = False
request.user.licence_id = validator.computed_licence_id
request.user.save()
@@ -688,7 +688,7 @@ def register_tournament(request, tournament_id):
)
stripped_license = None
- if request.user.licence_id is not None:
+ if request.user.is_authenticated and request.user.licence_id is not None:
stripped_license = LicenseValidator(request.user.licence_id).stripped_license
# Create PlayerRegistration objects for each player in the session
@@ -701,7 +701,7 @@ def register_tournament(request, tournament_id):
is_woman = player_data.get('is_woman', False)
- rank = player_data['rank']
+ rank = player_data.get('rank', 0)
computed_rank = None
sex = PlayerSexType.MALE
if is_woman is None:
@@ -731,8 +731,8 @@ def register_tournament(request, tournament_id):
rank = rank,
computed_rank = computed_rank,
licence_id=player_data['licence_id'],
- email = player_data.get('email', None),
- phone_number = player_data.get('phone_number', None)
+ email = team_form.cleaned_data['email'],
+ phone_number = team_form.cleaned_data['mobile_number']
)
team_registration.set_weight()
@@ -743,12 +743,12 @@ def register_tournament(request, tournament_id):
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:
+ user_licence_id = request.user.licence_id
initial_data = {
'email': request.user.email,
'phone': request.user.phone,