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()