From 8b75900103171ce346e0b407d400620e3bcf9c3c Mon Sep 17 00:00:00 2001 From: Jean-Romain Garnier Date: Fri, 17 Apr 2020 20:41:02 +0200 Subject: [PATCH] Make AdherentCreationForm code clearer --- users/forms.py | 6 +++--- users/views.py | 3 +-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/users/forms.py b/users/forms.py index effb9623..dea3c317 100644 --- a/users/forms.py +++ b/users/forms.py @@ -502,11 +502,11 @@ class AdherentCreationForm(AdherentForm): user = super(AdherentForm, self).save(commit=False) is_set_password_allowed = OptionalUser.get_cached_value("allow_set_password_during_user_creation") - send_email = not is_set_password_allowed or self.cleaned_data.get("init_password_by_mail") - if not send_email: + set_passwd = is_set_password_allowed and not self.cleaned_data.get("init_password_by_mail") + if set_passwd: user.set_password(self.cleaned_data["password1"]) - user.should_send_password_reset_email = send_email + user.did_set_initial_passwd = set_passwd user.save() return user diff --git a/users/views.py b/users/views.py index 2366e417..06f65dce 100644 --- a/users/views.py +++ b/users/views.py @@ -124,8 +124,7 @@ def new_user(request): is_set_password_allowed = OptionalUser.get_cached_value("allow_set_password_during_user_creation") if user.is_valid(): - # Use "is False" so that if None, the email is sent - if is_set_password_allowed and user.should_send_password_reset_email: + if user.did_set_initial_passwd: user.send_confirm_email_if_necessary(request) messages.success( request,