mirror of
https://gitlab.com/animath/si/plateforme.git
synced 2024-12-25 06:22:22 +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):
|
||||
if "name" in self.cleaned_data:
|
||||
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."))
|
||||
return name
|
||||
|
||||
@ -36,7 +36,7 @@ class TeamForm(forms.ModelForm):
|
||||
if not re.match("[A-Z]{3}", trigram):
|
||||
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."))
|
||||
return trigram
|
||||
|
||||
|
@ -82,6 +82,15 @@ class UserForm(forms.ModelForm):
|
||||
self.fields["last_name"].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:
|
||||
model = User
|
||||
fields = ('first_name', 'last_name', 'email',)
|
||||
|
Loading…
Reference in New Issue
Block a user