8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-11-23 11:53:12 +00:00

Improve comments for User clean methods

This commit is contained in:
Jean-Romain Garnier 2020-04-21 21:38:31 +02:00 committed by Gabriel Detraz
parent dc67ed5298
commit 5eb89e85ba

View file

@ -1330,8 +1330,9 @@ class User(
raise ValidationError(_("This username is already used."))
def clean_email(self, *args, **kwargs):
# Allow empty emails if the user had an empty email before
if not self.email and (self.__original_email or not self.pk):
# Allow empty emails only if the user had an empty email before
is_created = not self.pk
if not self.email and (self.__original_email or is_created):
raise forms.ValidationError(
_("Email field cannot be empty.")
)
@ -1346,9 +1347,9 @@ class User(
)
def clean(self, *args, **kwargs):
super(User, self).clean(*args, **kwargs)
"""Check if this pseudo is already used by any mailalias.
Better than raising an error in post-save and catching it"""
super(User, self).clean(*args, **kwargs)
self.clean_pseudo(*args, **kwargs)
self.clean_email(*args, **kwargs)