mirror of
https://gitlab.com/animath/si/plateforme.git
synced 2024-12-25 05:42:23 +00:00
Better unique validation errors
Signed-off-by: Emmy D'Anello <emmy.danello@animath.fr>
This commit is contained in:
parent
b40dce27df
commit
a240d7cad5
@ -26,7 +26,7 @@ class TeamForm(forms.ModelForm):
|
|||||||
def clean_name(self):
|
def clean_name(self):
|
||||||
if "name" in self.cleaned_data:
|
if "name" in self.cleaned_data:
|
||||||
name = self.cleaned_data["name"]
|
name = self.cleaned_data["name"]
|
||||||
if not self.instance.pk and Team.objects.filter(name=name).exists():
|
if Team.objects.filter(name=name).exclude(pk=self.instance.pk).exists():
|
||||||
raise ValidationError(_("This name is already used."))
|
raise ValidationError(_("This name is already used."))
|
||||||
return name
|
return name
|
||||||
|
|
||||||
@ -36,7 +36,7 @@ class TeamForm(forms.ModelForm):
|
|||||||
if not re.match("[A-Z]{3}", trigram):
|
if not re.match("[A-Z]{3}", trigram):
|
||||||
raise ValidationError(_("The trigram must be composed of three uppercase letters."))
|
raise ValidationError(_("The trigram must be composed of three uppercase letters."))
|
||||||
|
|
||||||
if not self.instance.pk and Team.objects.filter(trigram=trigram).exists():
|
if Team.objects.filter(trigram=trigram).exclude(pk=self.instance.pk).exists():
|
||||||
raise ValidationError(_("This trigram is already used."))
|
raise ValidationError(_("This trigram is already used."))
|
||||||
return trigram
|
return trigram
|
||||||
|
|
||||||
|
@ -82,6 +82,15 @@ class UserForm(forms.ModelForm):
|
|||||||
self.fields["last_name"].required = True
|
self.fields["last_name"].required = True
|
||||||
self.fields["email"].required = True
|
self.fields["email"].required = True
|
||||||
|
|
||||||
|
def clean_email(self):
|
||||||
|
"""
|
||||||
|
Ensure that the email address is unique.
|
||||||
|
"""
|
||||||
|
email = self.data["email"]
|
||||||
|
if User.objects.filter(email=email).exclude(pk=self.instance.pk).exists():
|
||||||
|
self.add_error("email", _("This email address is already used."))
|
||||||
|
return email
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = User
|
model = User
|
||||||
fields = ('first_name', 'last_name', 'email',)
|
fields = ('first_name', 'last_name', 'email',)
|
||||||
|
Loading…
Reference in New Issue
Block a user