# Generated by Django 2.2.3 on 2019-07-09 07:32

from django.db import migrations
import ee_site.apps.main.blocks
import wagtail.core.blocks
import wagtail.core.fields


def convert_field_to_streamfield(page, field_name):
    field = getattr(page, field_name)
    if field.raw_text and not field:
        setattr(page, field_name, [('text', field.raw_text)])


def convert_to_streamfield(apps, schema_editor):
    ProjectPage = apps.get_model("projects", "ProjectPage")
    for page in ProjectPage.objects.all():
        convert_field_to_streamfield(page, 'challenge')
        convert_field_to_streamfield(page, 'challenge_pl')
        convert_field_to_streamfield(page, 'challenge_en')
        page.save()


class Migration(migrations.Migration):

    dependencies = [
        ('projects', '0025_auto_20190709_0905'),
    ]

    operations = [
        migrations.AlterField(
            model_name='projectpage',
            name='challenge',
            field=wagtail.core.fields.StreamField([('text', wagtail.core.blocks.CharBlock(template='projects/blocks/paragraph.html')), ('tiles_list', ee_site.apps.main.blocks.HorizontalList(wagtail.core.blocks.StructBlock([('heading', wagtail.core.blocks.CharBlock()), ('description', wagtail.core.blocks.RichTextBlock(features=[]))])))], default=''),
            preserve_default=False,
        ),
        migrations.AlterField(
            model_name='projectpage',
            name='challenge_en',
            field=wagtail.core.fields.StreamField([('text', wagtail.core.blocks.CharBlock(template='projects/blocks/paragraph.html')), ('tiles_list', ee_site.apps.main.blocks.HorizontalList(wagtail.core.blocks.StructBlock([('heading', wagtail.core.blocks.CharBlock()), ('description', wagtail.core.blocks.RichTextBlock(features=[]))])))], null=True),
        ),
        migrations.AlterField(
            model_name='projectpage',
            name='challenge_pl',
            field=wagtail.core.fields.StreamField([('text', wagtail.core.blocks.CharBlock(template='projects/blocks/paragraph.html')), ('tiles_list', ee_site.apps.main.blocks.HorizontalList(wagtail.core.blocks.StructBlock([('heading', wagtail.core.blocks.CharBlock()), ('description', wagtail.core.blocks.RichTextBlock(features=[]))])))], null=True),
        ),
        migrations.RunPython(
            convert_to_streamfield,
        ),
    ]
