36 lines
1,000 B
Python
36 lines
1,000 B
Python
|
# -*- coding: utf-8 -*-
|
||
|
from django.db import migrations
|
||
|
|
||
|
|
||
|
def create_clipper_connections(apps, schema_editor):
|
||
|
CofProfile = apps.get_model("gestioncof", "CofProfile")
|
||
|
SocialAccount = apps.get_model("socialaccount", "SocialAccount")
|
||
|
|
||
|
profiles = CofProfile.objects.exclude(login_clipper="").values(
|
||
|
"user_id", "login_clipper"
|
||
|
)
|
||
|
|
||
|
SocialAccount.objects.bulk_create(
|
||
|
[
|
||
|
SocialAccount(
|
||
|
provider="clipper", user_id=p["user_id"], uid=p["login_clipper"]
|
||
|
)
|
||
|
for p in profiles
|
||
|
]
|
||
|
)
|
||
|
|
||
|
|
||
|
class Migration(migrations.Migration):
|
||
|
"""
|
||
|
As part of the allauth integration, this migration creates SocialAccount
|
||
|
instances for Clipper provider, based on the `CofProfile.login_clipper`
|
||
|
values.
|
||
|
"""
|
||
|
|
||
|
dependencies = [
|
||
|
("gestioncof", "0015_unique_login_clipper"),
|
||
|
("socialaccount", "0003_extra_data_default_dict"),
|
||
|
]
|
||
|
|
||
|
operations = [migrations.RunPython(create_clipper_connections)]
|