# -*- coding: utf-8 -*-
# Generated by Django 1.11.29 on 2021-09-23 15:15
from __future__ import unicode_literals

from django.db import migrations


def setup_display_emails(apps, schema_editor):
    Article = apps.get_model("submission", "Article")

    for article in Article.objects.all():
        if article.correspondence_author:
            article.frozenauthor_set.filter(
                author__pk=article.correspondence_author.pk,
            ).update(
                display_email=True,
            )
        else:
            first_author = article.frozenauthor_set.all().first()
            if first_author:
                first_author.display_email = True
                first_author.save()


class Migration(migrations.Migration):

    dependencies = [
        ('submission', '0060_auto_20210923_1545'),
    ]

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