timetoconfirm
Raz 8 months ago
parent e3a9d8ad06
commit d9a696d82e
  1. 49
      tournaments/forms.py
  2. 2
      tournaments/services/email_service.py
  3. 11
      tournaments/templates/profile.html

@ -12,6 +12,11 @@ from django.utils.encoding import force_bytes
class CustomUserCreationForm(UserCreationForm): class CustomUserCreationForm(UserCreationForm):
usable_password = None 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: class Meta:
model = CustomUser model = CustomUser
@ -33,6 +38,22 @@ class CustomUserCreationForm(UserCreationForm):
class SimpleCustomUserCreationForm(UserCreationForm): class SimpleCustomUserCreationForm(UserCreationForm):
usable_password = None 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: class Meta:
model = CustomUser model = CustomUser
fields = UserCreationForm.Meta.fields + ('email', 'phone', 'first_name', 'last_name', 'licence_id', 'country') 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): def clean_licence_id(self):
licence_id = self.cleaned_data.get('licence_id') licence_id = self.cleaned_data.get('licence_id')
if licence_id:
# Convert to uppercase licence_id = licence_id.replace(' ', '').strip().upper()
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}")
return licence_id return licence_id
def clean_last_name(self): def clean_last_name(self):
@ -193,6 +206,22 @@ class ProfileUpdateForm(forms.ModelForm):
# Remove autofocus from the 'username' field # Remove autofocus from the 'username' field
self.fields['username'].widget.attrs.pop("autofocus", None) 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: class Meta:
model = CustomUser model = CustomUser
fields = ['first_name', 'last_name', 'licence_id', 'username', 'email', 'phone'] fields = ['first_name', 'last_name', 'licence_id', 'username', 'email', 'phone']

@ -75,7 +75,7 @@ class TournamentEmailService:
body_parts.append(f"Votre inscription en liste d'attente du tournoi {tournament_details_str} est confirmée.") body_parts.append(f"Votre inscription en liste d'attente du tournoi {tournament_details_str} est confirmée.")
else: else:
body_parts.append(f"Votre inscription au tournoi {tournament_details_str} est confirmée.") 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") cloture_date = tournament.local_registration_federal_limit().strftime("%d/%m/%Y à %H:%M")
loc = "" loc = ""
if cloture_date is not None: if cloture_date is not None:

@ -23,17 +23,6 @@
<div class="cell medium-6 large-6 topblock my-block"> <div class="cell medium-6 large-6 topblock my-block">
<div class="bubble"> <div class="bubble">
<label class="title">Mes informations</label> <label class="title">Mes informations</label>
{% if form.errors %}
<div class="alert">
{% for field, errors in form.errors.items %}
{% for error in errors %}
<p>{{ error }}</p>
{% endfor %}
{% endfor %}
</div>
{% endif %}
<!-- Add non-field errors (if any) -->
{% if form.non_field_errors %} {% if form.non_field_errors %}
<div class="alert"> <div class="alert">
{% for error in form.non_field_errors %} {% for error in form.non_field_errors %}

Loading…
Cancel
Save