# Generated by Django 2.2.9 on 2020-01-06 11:33

from django.db import migrations


# pylint: disable=unused-argument
def forwards(apps, schema_editor):
    TranslatablePage = apps.get_model("wagtailtrans", "TranslatablePage")
    Language = apps.get_model("wagtailtrans", "Language")
    AbstractBasePage = apps.get_model("ocyan_plugin_wagtail", "AbstractBasePage")
    default_language = Language.objects.filter(is_default=True).first()

    for page in AbstractBasePage.objects.all():
        d = TranslatablePage(
            translatable_page_ptr_id=page.page_ptr_id, language=default_language
        )
        d.save_base(raw=True)


def backwards(apps, schema_editor):
    TranslatablePage = apps.get_model("wagtailtrans", "TranslatablePage")
    TranslatablePage.objects.all().delete(raw=True)


class Migration(migrations.Migration):
    dependencies = [
        ("wagtailtrans", "0009_create_initial_language"),
        ("ocyan_plugin_wagtail", "0003_page_ptr_manual"),
    ]
    replaces = [
        ("ocyan_plugin_wagtail", "0015_fill_translatable_pages"),
    ]
    operations = [
        migrations.RunPython(forwards, backwards),
    ]
