From df75e676e0669c405dbef8438b390cf6ab12ff85 Mon Sep 17 00:00:00 2001 From: Jorran de Wit <jorrandewit@outlook.com> Date: Wed, 27 Mar 2019 10:30:31 +0100 Subject: [PATCH] Fix register bug --- scipost/forms.py | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/scipost/forms.py b/scipost/forms.py index 0c49dce9a..f2c76f3f9 100644 --- a/scipost/forms.py +++ b/scipost/forms.py @@ -154,10 +154,14 @@ class RegistrationForm(forms.Form): 'password': self.cleaned_data['password'], 'is_active': False }) - institution, __ = Institution.objects.get_or_create( - country=self.cleaned_data['country_of_employment'], - name=self.cleaned_data['affiliation'], - ) + try: + institution = Institution.objects.filter( + country=self.cleaned_data['country_of_employment'], + name=self.cleaned_data['affiliation']).first() + except Institution.DoesNotExist: + institution = Institution.objects.create( + country=self.cleaned_data['country_of_employment'], + name=self.cleaned_data['affiliation']) contributor, __ = Contributor.objects.get_or_create(**{ 'user': user, 'invitation_key': self.cleaned_data.get('invitation_key', ''), @@ -167,10 +171,13 @@ class RegistrationForm(forms.Form): 'personalwebpage': self.cleaned_data['personalwebpage'], 'accepts_SciPost_emails': self.cleaned_data['subscribe'], }) - affiliation, __ = Affiliation.objects.get_or_create( - contributor=contributor, - institution=institution, - ) + try: + Affiliation.objects.filter( + contributor=contributor, institution=institution).first() + except Affiliation.DoesNotExist: + Affiliation.objects.create( + contributor=contributor, institution=institution) + contributor.save() return contributor -- GitLab