Script to copy mail addresses
This commit is contained in:
parent
d28e195873
commit
70ff24c708
1 changed files with 29 additions and 0 deletions
29
scripts/initalize_allauth.py
Normal file
29
scripts/initalize_allauth.py
Normal 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()
|
Loading…
Reference in a new issue