|
|
|
@ -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'] |
|
|
|
|