30 lines
927 B
Python
30 lines
927 B
Python
|
|
||
|
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()
|