2023-11-13 17:09:37 +00:00
|
|
|
import re
|
|
|
|
|
|
|
|
from django import forms
|
|
|
|
from django.utils.translation import gettext_lazy as _
|
2024-01-04 15:27:27 +00:00
|
|
|
from idhub_auth.models import User
|
2023-11-13 17:09:37 +00:00
|
|
|
|
|
|
|
|
|
|
|
class ProfileForm(forms.ModelForm):
|
|
|
|
first_name = forms.CharField(required=True)
|
|
|
|
last_name = forms.CharField(required=True)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = User
|
2024-02-26 10:03:07 +00:00
|
|
|
fields = ['first_name', 'last_name', 'email', 'is_admin']
|
2023-11-13 17:09:37 +00:00
|
|
|
|
|
|
|
def clean_first_name(self):
|
|
|
|
first_name = super().clean()['first_name']
|
2023-11-22 13:05:24 +00:00
|
|
|
match = r'^[a-zA-ZäöüßÄÖÜáéíóúàèìòùÀÈÌÒÙÁÉÍÓÚßñÑçÇ\s\'-]+'
|
2023-12-14 16:15:22 +00:00
|
|
|
if not re.fullmatch(match, first_name):
|
2023-11-13 17:09:37 +00:00
|
|
|
txt = _("The string must contain only characters and spaces")
|
|
|
|
raise forms.ValidationError(txt)
|
|
|
|
|
|
|
|
return first_name
|
|
|
|
|
|
|
|
def clean_last_name(self):
|
|
|
|
last_name = super().clean()['last_name']
|
2023-11-22 13:05:24 +00:00
|
|
|
match = r'^[a-zA-ZäöüßÄÖÜáéíóúàèìòùÀÈÌÒÙÁÉÍÓÚßñÑçÇ\s\'-]+'
|
2023-12-14 16:15:22 +00:00
|
|
|
if not re.fullmatch(match, last_name):
|
2023-11-13 17:09:37 +00:00
|
|
|
txt = _("The string must contain only characters and spaces")
|
|
|
|
raise forms.ValidationError(txt)
|
|
|
|
|
|
|
|
return last_name
|
|
|
|
|