# -*- coding: utf-8 -*-
# Generated by Django 1.9 on 2016-10-06 15:54
from __future__ import unicode_literals

from django.db import migrations


def convert_attribute_long_names(apps, schema_editor):
    AttributeType = apps.get_model('jsonattrs', 'AttributeType')
    Attribute = apps.get_model('jsonattrs', 'Attribute')

    # Empty database?  Probably during testing...
    if not AttributeType.objects.exists():
        return

    for attr in Attribute.objects.all():
        attr.long_name_xlat = attr.long_name
        attr.save()


def convert_choice_labels(apps, schema_editor):
    AttributeType = apps.get_model('jsonattrs', 'AttributeType')
    Attribute = apps.get_model('jsonattrs', 'Attribute')

    # Empty database?  Probably during testing...
    if not AttributeType.objects.exists():
        return

    for attr in Attribute.objects.all():
        attr.choice_labels_xlat = attr.choice_labels
        attr.save()


class Migration(migrations.Migration):

    dependencies = [
        ('jsonattrs', '0003_prepare_multilingual_setup'),
    ]

    operations = [
        migrations.RunPython(
            code=convert_attribute_long_names,
            reverse_code=migrations.operations.special.RunPython.noop,
        ),
        migrations.RunPython(
            code=convert_choice_labels,
            reverse_code=migrations.operations.special.RunPython.noop,
        ),
    ]
