# -*- coding: utf-8 -*-
# Generated by Django 1.9.1 on 2016-02-17 10:30
from __future__ import unicode_literals

from django.db import migrations


def create_new_resources_index_page(apps, schema_editor):
    '''
    Transfer data from the resource page (an instance of RTEIPage) to a new
    instance of ResourceIndexPage. This deletes the old resources (RTEIPage) page.
    '''
    from rtei.translation import RTEIPageTR, ResourceIndexPageTR
    from modeltranslation.translator import translator
    from django.contrib.contenttypes.models import ContentType

    RTEIPage = apps.get_model("rtei", "RTEIPage")
    translator.register(RTEIPage, RTEIPageTR)
    ResourceIndexPage = apps.get_model('rtei', 'ResourceIndexPage')
    translator.register(ResourceIndexPage, ResourceIndexPageTR)

    resource_index_page_content_type = ContentType.objects.get_for_model(ResourceIndexPage)

    old_resources_page = RTEIPage.objects.get(slug='resources')
    old_resources_page.delete()

    d = {
        'slug': old_resources_page.slug,
        'slug_en': old_resources_page.slug_en,
        'slug_fr': old_resources_page.slug_fr,
        'slug_es': old_resources_page.slug_es,
        'slug_ar': old_resources_page.slug_ar,
        'numchild': old_resources_page.numchild,
        'title': old_resources_page.title,
        'title_en': old_resources_page.title_en,
        'title_fr': old_resources_page.title_fr,
        'title_es': old_resources_page.title_es,
        'title_ar': old_resources_page.title_ar,
        'url_path': old_resources_page.url_path,
        'url_path_en': old_resources_page.url_path_en,
        'url_path_fr': old_resources_page.url_path_fr,
        'url_path_es': old_resources_page.url_path_es,
        'url_path_ar': old_resources_page.url_path_ar,
        'show_in_menus': old_resources_page.show_in_menus,
        'path': old_resources_page.path,
        'depth': old_resources_page.depth,
        'content_type_id': resource_index_page_content_type.id
    }

    new_resources_page = ResourceIndexPage(**d)
    new_resources_page.save()


class Migration(migrations.Migration):

    dependencies = [
        ('rtei', '0005_resource_model'),
    ]

    operations = [
        migrations.RunPython(create_new_resources_index_page),
    ]

# -*- coding: utf-8 -*-
# Generated by Django 1.9.1 on 2016-02-17 10:30
from __future__ import unicode_literals

from django.db import migrations


def create_new_resources_index_page(apps, schema_editor):
    '''
    Transfer data from the resource page (an instance of RTEIPage) to a new
    instance of ResourceIndexPage. This deletes the old resources (RTEIPage)
    page.
    '''
    from django.contrib.contenttypes.models import ContentType

    RTEIPage = apps.get_model("rtei", "RTEIPage")
    ResourceIndexPage = apps.get_model('rtei', 'ResourceIndexPage')

    resource_index_page_content_type = ContentType.objects.get_for_model(
        ResourceIndexPage)

    old_resources_page = RTEIPage.objects.get(slug='resources')
    old_resources_page.delete()

    d = {
        'slug': old_resources_page.slug,
        'slug_en': old_resources_page.slug_en,
        'slug_fr': old_resources_page.slug_fr,
        'slug_es': old_resources_page.slug_es,
        'slug_ar': old_resources_page.slug_ar,
        'numchild': old_resources_page.numchild,
        'title': old_resources_page.title,
        'title_en': old_resources_page.title_en,
        'title_fr': old_resources_page.title_fr,
        'title_es': old_resources_page.title_es,
        'title_ar': old_resources_page.title_ar,
        'url_path': old_resources_page.url_path,
        'url_path_en': old_resources_page.url_path_en,
        'url_path_fr': old_resources_page.url_path_fr,
        'url_path_es': old_resources_page.url_path_es,
        'url_path_ar': old_resources_page.url_path_ar,
        'show_in_menus': old_resources_page.show_in_menus,
        'path': old_resources_page.path,
        'depth': old_resources_page.depth,
        'content_type_id': resource_index_page_content_type.id
    }

    new_resources_page = ResourceIndexPage(**d)
    new_resources_page.save()


class Migration(migrations.Migration):

    dependencies = [
        ('rtei', '0005_resource_model'),
    ]

    operations = [
        migrations.RunPython(create_new_resources_index_page),
    ]

Remove translation steps from migrations