# Generated by Django 3.1.8 on 2021-10-01 12:47

from django.db import migrations


def copy_userprofiles(apps, schema_editor):
    if not apps.is_installed('wagtailusers'):
        return

    UserProfile = apps.get_model('wagtailcore.UserProfile')
    OldUserProfile = apps.get_model('wagtailusers.UserProfile')
    UserProfile.objects.bulk_create(
        [
            UserProfile(
                user_id=user_profile.user_id,
                submitted_notifications=user_profile.submitted_notifications,
                approved_notifications=user_profile.approved_notifications,
                rejected_notifications=user_profile.rejected_notifications,
                updated_comments_notifications=user_profile.updated_comments_notifications,
                preferred_language=user_profile.preferred_language,
                current_time_zone=user_profile.current_time_zone,
                avatar=user_profile.avatar,  # TODO does this copy the avatar?
            )
            for user_profile in OldUserProfile.objects.all()
        ],
        ignore_conflicts=True
    )


class Migration(migrations.Migration):

    dependencies = [
        ('wagtailcore', '0067_userprofile'),
    ]

    operations = [
        migrations.RunPython(copy_userprofiles, migrations.RunPython.noop),
    ]
