From 70ff24c7080d39999c373f5b493f73e0db72cf47 Mon Sep 17 00:00:00 2001 From: Evarin Date: Sat, 29 Dec 2018 00:42:35 +0100 Subject: [PATCH] Script to copy mail addresses --- scripts/initalize_allauth.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 scripts/initalize_allauth.py diff --git a/scripts/initalize_allauth.py b/scripts/initalize_allauth.py new file mode 100644 index 0000000..7e69c1d --- /dev/null +++ b/scripts/initalize_allauth.py @@ -0,0 +1,29 @@ + +from allauth.account.models import EmailAddress +from allauth.socialaccount.models import SocialAccount + +accts = SocialAccount.objects.all() + +# Create email addresses + +for acc in accts: + u = acc.user + print(u.username) + emls = EmailAddress.objects.filter(user=u, email_endswith="clipper.ens.fr") + try: + cpeml = acc.extra_data["ldap"]["email"] + except KeyError: + cpeml = "%s@clipper.ens.fr" % acc.uid + + + ml = EmailAddress(email=cpeml, user=u, verified=True, primary=True) + if u.profil.mail != cpeml and u.profil.mail: + ml.primary = False + print(" Creating other primary address", u.profil.mail) + ml2 = EmailAddress(email=u.profil.mail, user=u, verified=True, primary=True) + ml2.save() + if emls.exists(): + print(" Clipper already exists", emls.values_list("email", flat=True)) + else: + print(" Saving Clipper", cpeml) + ml.save()