From d9a696d82ee37e96c228eb6894a6175e2a6e152b Mon Sep 17 00:00:00 2001 From: Raz Date: Sat, 29 Mar 2025 18:45:44 +0100 Subject: [PATCH] fix crash --- tournaments/forms.py | 49 +++++++++++++++++++++------ tournaments/services/email_service.py | 2 +- tournaments/templates/profile.html | 11 ------ 3 files changed, 40 insertions(+), 22 deletions(-) diff --git a/tournaments/forms.py b/tournaments/forms.py index cc4d314..872514b 100644 --- a/tournaments/forms.py +++ b/tournaments/forms.py @@ -12,6 +12,11 @@ from django.utils.encoding import force_bytes class CustomUserCreationForm(UserCreationForm): usable_password = None + def clean_licence_id(self): + licence_id = self.cleaned_data.get('licence_id') + if licence_id: + return licence_id.replace(' ', '').strip().upper() + return licence_id class Meta: model = CustomUser @@ -33,6 +38,22 @@ class CustomUserCreationForm(UserCreationForm): class SimpleCustomUserCreationForm(UserCreationForm): usable_password = None + def clean_licence_id(self): + licence_id = self.cleaned_data.get('licence_id') + if licence_id: + return licence_id.replace(' ', '').strip().upper() + return licence_id + + def clean_phone(self): + phone = self.cleaned_data.get('phone') + if phone: + # Remove all spaces + phone = phone.replace(' ', '') + # Basic regex for phone numbers, matching common formats + if not re.match(r"^\+?\d{10,15}$", phone): + raise forms.ValidationError("Entrer un numéro de téléphone valide.") + return phone + class Meta: model = CustomUser fields = UserCreationForm.Meta.fields + ('email', 'phone', 'first_name', 'last_name', 'licence_id', 'country') @@ -125,16 +146,8 @@ class AddPlayerForm(forms.Form): def clean_licence_id(self): licence_id = self.cleaned_data.get('licence_id') - - # Convert to uppercase - licence_id = licence_id.upper() - - # Update the cleaned_data with the modified licence_id - self.cleaned_data['licence_id'] = licence_id - - # Optionally, print the cleaned license ID for debugging - print(f"Cleaned Licence ID (inside clean_licence_id): {licence_id}") - + if licence_id: + licence_id = licence_id.replace(' ', '').strip().upper() return licence_id def clean_last_name(self): @@ -193,6 +206,22 @@ class ProfileUpdateForm(forms.ModelForm): # Remove autofocus from the 'username' field self.fields['username'].widget.attrs.pop("autofocus", None) + def clean_licence_id(self): + licence_id = self.cleaned_data.get('licence_id') + if licence_id: + return licence_id.replace(' ', '').upper() + return licence_id + + def clean_phone(self): + phone = self.cleaned_data.get('phone') + if phone: + # Remove all spaces + phone = phone.replace(' ', '') + # Basic regex for phone numbers, matching common formats + if not re.match(r"^\+?\d{10,15}$", phone): + raise forms.ValidationError("Entrer un numéro de téléphone valide.") + return phone + class Meta: model = CustomUser fields = ['first_name', 'last_name', 'licence_id', 'username', 'email', 'phone'] diff --git a/tournaments/services/email_service.py b/tournaments/services/email_service.py index 33fe93f..f8f904c 100644 --- a/tournaments/services/email_service.py +++ b/tournaments/services/email_service.py @@ -75,7 +75,7 @@ class TournamentEmailService: body_parts.append(f"Votre inscription en liste d'attente du tournoi {tournament_details_str} est confirmée.") else: body_parts.append(f"Votre inscription au tournoi {tournament_details_str} est confirmée.") - if tournament.team_sort == TeamSortingType.RANK: + if tournament.team_sorting == TeamSortingType.RANK: cloture_date = tournament.local_registration_federal_limit().strftime("%d/%m/%Y à %H:%M") loc = "" if cloture_date is not None: diff --git a/tournaments/templates/profile.html b/tournaments/templates/profile.html index 89fd5f4..9216b92 100644 --- a/tournaments/templates/profile.html +++ b/tournaments/templates/profile.html @@ -23,17 +23,6 @@
- {% if form.errors %} -
- {% for field, errors in form.errors.items %} - {% for error in errors %} -

{{ error }}

- {% endfor %} - {% endfor %} -
- {% endif %} - - {% if form.non_field_errors %}
{% for error in form.non_field_errors %}