From 2a068a7e0a0d98749b8b8c58122d80c844064d2c Mon Sep 17 00:00:00 2001 From: Jean-Romain Garnier Date: Fri, 17 Apr 2020 18:01:35 +0200 Subject: [PATCH] Fix error preventing migration --- users/forms.py | 71 +++++++++++++++++++++++++++----------------------- 1 file changed, 38 insertions(+), 33 deletions(-) diff --git a/users/forms.py b/users/forms.py index 94002eeb..a29c1fbe 100644 --- a/users/forms.py +++ b/users/forms.py @@ -405,41 +405,40 @@ class AdherentCreationForm(AdherentForm): AdherentForm auquel on ajoute une checkbox afin d'éviter les doublons d'utilisateurs et, optionnellement, un champ mot de passe""" - if OptionalUser.get_cached_value("allow_set_password_during_user_creation"): - # Champ pour choisir si un lien est envoyé par mail pour le mot de passe - init_password_by_mail_info = _( - "If this options is set, you will receive a link to set" - " your initial password by email. If you do not have" - " any means of accessing your emails, you can disable" - " this option to set your password immediatly." - " You will still receive an email to confirm your address." - " Failure to confirm your address will result in an" - " automatic suspension of your account until you do." - ) + # Champ pour choisir si un lien est envoyé par mail pour le mot de passe + init_password_by_mail_info = _( + "If this options is set, you will receive a link to set" + " your initial password by email. If you do not have" + " any means of accessing your emails, you can disable" + " this option to set your password immediatly." + " You will still receive an email to confirm your address." + " Failure to confirm your address will result in an" + " automatic suspension of your account until you do." + ) - init_password_by_mail = forms.BooleanField( - help_text=init_password_by_mail_info, - required=False, - initial=True - ) - init_password_by_mail.label = _("Send password reset link by email.") + init_password_by_mail = forms.BooleanField( + help_text=init_password_by_mail_info, + required=False, + initial=True + ) + init_password_by_mail.label = _("Send password reset link by email.") - # Champs pour initialiser le mot de passe - # Validators are handled manually since theses fields aren't always required - password1 = forms.CharField( - required=False, - label=_("Password"), - widget=forms.PasswordInput, - #validators=[MinLengthValidator(8)], - max_length=255, - ) - password2 = forms.CharField( - required=False, - label=_("Password confirmation"), - widget=forms.PasswordInput, - #validators=[MinLengthValidator(8)], - max_length=255, - ) + # Champs pour initialiser le mot de passe + # Validators are handled manually since theses fields aren't always required + password1 = forms.CharField( + required=False, + label=_("Password"), + widget=forms.PasswordInput, + #validators=[MinLengthValidator(8)], + max_length=255, + ) + password2 = forms.CharField( + required=False, + label=_("Password confirmation"), + widget=forms.PasswordInput, + #validators=[MinLengthValidator(8)], + max_length=255, + ) # Champ permettant d'éviter au maxium les doublons d'utilisateurs former_user_check_info = _( @@ -481,6 +480,12 @@ class AdherentCreationForm(AdherentForm): ) ) + # Remove password fields if option is disabled + if not OptionalUser.get_cached_value("allow_set_password_during_user_creation"): + self.fields.pop("init_password_by_mail") + self.fields.pop("password1") + self.fields.pop("password2") + def clean_password1(self): """Ignore ce champs si la case init_password_by_mail est décochée""" send_email = self.cleaned_data.get("init_password_by_mail")