From fa6531c1df1e0d9d896aa391c2413df1a8dc86dc Mon Sep 17 00:00:00 2001 From: Max Yakovenko Date: Sat, 21 Jul 2018 11:42:55 +0300 Subject: [PATCH] refactor accounts ext forms --- accounts_ext/forms.py | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/accounts_ext/forms.py b/accounts_ext/forms.py index d47661e..e06d7b8 100644 --- a/accounts_ext/forms.py +++ b/accounts_ext/forms.py @@ -63,15 +63,13 @@ class RegistrationForm(RegistrationFormUniqueEmail): def save(self, commit=True): user = super().save(commit) profile = Profile.objects.filter(user=user).first() - if profile: - profile.first_name = self.cleaned_data['first_name'] - profile.last_name = self.cleaned_data['last_name'] - profile.patronymic = self.cleaned_data['patronymic'] - profile.save() - else: - logger.error( - msg="User {user_email} missing profile object".format({'user_email': self.cleaned_data['email']}) - ) + if not profile: + profile = Profile() + + profile.first_name = self.cleaned_data['first_name'] + profile.last_name = self.cleaned_data['last_name'] + profile.patronymic = self.cleaned_data['patronymic'] + profile.save() return user