# Generated by Django 2.2.11 on 2020-04-16 10:38

from django.db import migrations


def convert_resources_subpage_body_to_snippet(apps, schema_editor):
    LandingPage = apps.get_model("contentPages", "LandingPage")
    SharedContent = apps.get_model("contentPages", "SharedContent")
    landing_pages = LandingPage.objects.all()
    for landing_page in landing_pages:
        resources_body = landing_page.resources_subpage_body
        resources_title = "{0} - {1}".format(landing_page.title, landing_page.resources_subpage_heading)
        snippet = SharedContent(content_body=resources_body, title=resources_title)
        snippet.save()
        landing_page.resources_subpage_body = snippet.id
        landing_page.save()


class Migration(migrations.Migration):

    dependencies = [
        ('contentPages', '0015_auto_20200416_1028'),
        ('contentPages', '0018_auto_20200414_1332'),
    ]

    operations = [
        migrations.RunPython(convert_resources_subpage_body_to_snippet),
    ]
