# -*- coding: utf-8 -*-
# Generated by Django 1.11.1 on 2017-12-13 15:48
from __future__ import unicode_literals

from django.db import migrations, models

from scripts.helpers import jurisdiction_translation_long_name as long_names


def create_long_names(apps, schema_editor):
    Jurisdiction = apps.get_model("capdb", "Jurisdiction")
    for jur in Jurisdiction.objects.all():
        if jur.name in long_names:
            jur.name_long = long_names[jur.name]
        else:
            jur.name_long = jur.name
        jur.save()


def remove_long_names(apps, schema_editor):
    Jurisdiction = apps.get_model("capdb", "Jurisdiction")
    for jur in Jurisdiction.objects.all():
        jur.name_long = ''
        jur.save()


class Migration(migrations.Migration):

    dependencies = [
        ('capdb', '0012_auto_20171116_2045'),
    ]

    operations = [
        migrations.RemoveField(
            model_name='jurisdiction',
            name='name_abbreviation',
        ),
        migrations.AddField(
            model_name='jurisdiction',
            name='name_long',
            field=models.CharField(blank=True, max_length=100),
        ),
        migrations.RunPython(create_long_names, remove_long_names),
    ]

