From 90a8605c209de257df5aede7e376ff75c0187e22 Mon Sep 17 00:00:00 2001
From: "J.-S. Caux" <J.S.Caux@uva.nl>
Date: Tue, 2 Apr 2019 20:26:23 +0200
Subject: [PATCH] Improve treatment of emails upon registration

---
 scipost/forms.py | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/scipost/forms.py b/scipost/forms.py
index 225d07282..8b5d9a842 100644
--- a/scipost/forms.py
+++ b/scipost/forms.py
@@ -186,10 +186,10 @@ class RegistrationForm(forms.Form):
                 orcid_id=self.cleaned_data['orcid_id'],
                 webpage=self.cleaned_data['personalwebpage'])
         # Add a ProfileEmail to this Profile
-        ProfileEmail.objects.get_or_create(
-            profile=profile,
-            email=self.cleaned_data['email'],
-            primary=True)
+        profile_email = ProfileEmail.objects.get_or_create(
+            profile=profile, email=self.cleaned_data['email'])
+        profile.emails.update(primary=False)
+        profile.emails.filter(id=profile_email.id).update(primary=True, still_valid=True)
         # Create an Affiliation for this Profile
         current_affiliation = self.cleaned_data.get('current_affiliation', None)
         if current_affiliation:
-- 
GitLab