# Generated by Django 2.2.6 on 2019-12-10 17:41

from django.db import migrations


def create_homepage(apps, schema_editor):
    # Get models
    ContentType = apps.get_model("contenttypes.ContentType")
    Page = apps.get_model("wagtailcore.Page")
    Site = apps.get_model("wagtailcore.Site")
    TestHomePage = apps.get_model("wagtail_localize_test.TestHomePage")

    # Delete the default homepage
    Page.objects.get(id=2).delete()

    # Create content type for homepage model
    homepage_content_type, created = ContentType.objects.get_or_create(
        model="testhomepage", app_label="wagtail_localize_test"
    )

    # Create a new homepage
    homepage = TestHomePage.objects.create(
        title="Home",
        draft_title="Home",
        slug="home",
        content_type=homepage_content_type,
        path="00010001",
        depth=2,
        numchild=0,
        url_path="/home/",
    )

    # Create a site with the new homepage set as the root
    Site.objects.create(hostname="localhost", root_page=homepage, is_default_site=True)


class Migration(migrations.Migration):

    dependencies = [("wagtail_localize_test", "0004_testhomepage")]

    operations = [migrations.RunPython(create_homepage)]
