8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-12-23 15:33:45 +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 Jean-Romain Garnier
parent e47b555343
commit 91a4c35d3b

View file

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