fix issue with unlicensed user and force mobile phone input

bracket-feature
Raz 10 months ago
parent 19d8c26869
commit 13c545f391
  1. 5
      tournaments/forms.py
  2. 26
      tournaments/services/tournament_registration.py
  3. 8
      tournaments/templates/register_tournament.html
  4. 4
      tournaments/views.py

@ -86,9 +86,9 @@ class TournamentRegistrationForm(forms.Form):
#last_name = forms.CharField(label='Nom', max_length=50)
email = forms.EmailField(label='E-mail', widget=forms.EmailInput(attrs={'readonly': 'readonly'}))
mobile_number = forms.CharField(
label='Téléphone (facultatif)',
label='Téléphone',
max_length=15,
required=False
required=True
)
def clean_mobile_number(self):
@ -106,6 +106,7 @@ class AddPlayerForm(forms.Form):
first_name = forms.CharField(label='Prénom', min_length=2, max_length=50, required=False)
last_name = forms.CharField(label='Nom', min_length=2, max_length=50, required=False)
first_tournament = False
user_without_licence = False
def names_is_valid(self):
first_name = self.cleaned_data.get('first_name')

@ -64,6 +64,12 @@ class TournamentRegistrationService:
if not self.context['team_form'].is_valid():
return
if self.request.user.is_authenticated:
cleaned_data = self.context['team_form'].cleaned_data
mobile_number = cleaned_data.get('mobile_number')
self.request.user.phone = mobile_number
self.request.user.save()
waiting_list_position = self.tournament.get_waiting_list_position()
team_registration = self.repository.create_team_registration(
@ -98,6 +104,9 @@ class TournamentRegistrationService:
self.request.session['team_registration'] = []
self.request.session['team_registration'].append(player_data)
self.context['current_players'] = self.request.session.get('team_registration', [])
self.context['add_player_form'].first_tournament = False
self.context['add_player_form'].user_without_licence = False
self.request.session.modified = True
def clear_session_data(self):
@ -109,7 +118,7 @@ class TournamentRegistrationService:
if self.request.user.is_authenticated:
initial_data = {
'email': self.request.user.email,
'phone': self.request.user.phone,
'mobile_number': self.request.user.phone,
}
return TournamentRegistrationForm(initial=initial_data)
@ -136,7 +145,7 @@ class TournamentRegistrationService:
'last_name': self.request.user.last_name.upper(),
}
self.context['add_player_form'] = AddPlayerForm(initial=player_data)
self.request.session['user_without_licence'] = True
self.context['add_player_form'].user_without_licence = True
self.request.session.modified = True
def _get_authenticated_user_data(self):
@ -208,8 +217,11 @@ class TournamentRegistrationService:
if self.request.user.is_authenticated and self.request.user.licence_id is None:
self._update_user_license(player_data.get('licence_id'))
self.context['add_player_form'].user_without_licence = False
self.request.session.modified = True
self.context['add_player_form'] = AddPlayerForm()
self.context['add_player_form'].first_tournament = False
def _handle_invalid_names(self, licence_id, player_data):
if not self.context['add_player_form'].first_tournament:
@ -237,9 +249,15 @@ class TournamentRegistrationService:
player_data['is_woman'] = self.request.session.get('is_woman', False)
def _update_user_license(self, licence_id):
self.request.session['user_without_licence'] = False
self.request.user.licence_id = LicenseValidator(licence_id).computed_licence_id
if self.request.user.is_authenticated and licence_id:
self.context['add_player_form'].user_without_licence = False
validator = LicenseValidator(licence_id)
self.request.user.licence_id = validator.computed_licence_id
self.request.user.save()
self.request.user.refresh_from_db()
# Reset the form state
self.context['add_player_form'] = AddPlayerForm()
self.context['add_player_form'].first_tournament = False
def _update_player_data_from_csv(self, player_data, csv_data):
player_data.update({

@ -61,7 +61,7 @@
Inscrivez votre partenaire
</div>
{% endif %}
{% if user_without_licence and tournament.license_is_required %}
{% if current_players|length == 0 and add_player_form.user_without_licence and tournament.license_is_required %}
<div class="semibold">
Une licence est obligatoire pour vous inscrire :
</div>
@ -71,8 +71,8 @@
{{ add_player_form.licence_id.label_tag }}
{{ add_player_form.licence_id }}
{% 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 add_player_form.first_tournament or add_player_form.user_without_licence or tournament.license_is_required is False %}
{% if not add_player_form.user_without_licence and tournament.license_is_required is True %}
<div class="semibold">
Précisez les informations du joueur :
</div>
@ -95,7 +95,7 @@
</div>
<button type="submit" name="add_player" class="rounded-button">
{% if user_without_licence %}
{% if add_player_form.user_without_licence %}
Confirmer
{% else %}
{% if current_players|length == 0 %}

@ -659,10 +659,6 @@ def send_verification_email(request, user, next_url):
@login_required
def profile(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
return render(request, 'registration/profile.html', {
'user_name': user.username
})

Loading…
Cancel
Save