Script to copy mail addresses

This commit is contained in:
Evarin 2018-12-29 00:42:35 +01:00
parent d28e195873
commit 70ff24c708

View file

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