From 77a1b39dbf87c46b400f95dcea71fe14bc32d362 Mon Sep 17 00:00:00 2001 From: Jean-Romain Garnier Date: Tue, 21 Apr 2020 17:07:09 +0200 Subject: [PATCH] Add required for email field when necessary --- users/forms.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/users/forms.py b/users/forms.py index 2f3c2e86..01820286 100644 --- a/users/forms.py +++ b/users/forms.py @@ -145,6 +145,7 @@ class UserCreationForm(FormRevMixin, forms.ModelForm): def __init__(self, *args, **kwargs): prefix = kwargs.pop("prefix", self.Meta.model.__name__) super(UserCreationForm, self).__init__(*args, prefix=prefix, **kwargs) + self.fields["email"].required = True def clean_email(self): new_email = self.cleaned_data.get("email") @@ -471,6 +472,7 @@ class AdherentCreationForm(AdherentForm): def __init__(self, *args, **kwargs): super(AdherentCreationForm, self).__init__(*args, **kwargs) gtu_file = GeneralOption.get_cached_value("GTU") + self.fields["email"].required = True self.fields["gtu_check"].label = mark_safe( "%s %s." % ( @@ -537,6 +539,7 @@ class AdherentEditForm(AdherentForm): "Leave empty if you don't have any GPG key." ) self.user = kwargs["instance"] + self.fields["email"].required = self.user.email and len(self.user.email) if "shell" in self.fields: self.fields["shell"].empty_label = _("Default shell") @@ -867,6 +870,7 @@ class EmailSettingsForm(FormRevMixin, FieldPermissionFormMixin, ModelForm): super(EmailSettingsForm, self).__init__(*args, prefix=prefix, **kwargs) self.user = kwargs["instance"] self.fields["email"].label = _("Main email address") + self.fields["email"].required = self.user.email and len(self.user.email) if "local_email_redirect" in self.fields: self.fields["local_email_redirect"].label = _("Redirect local emails") if "local_email_enabled" in self.fields: