# -*- coding: utf-8 -*-
# Generated by Django 1.9.6 on 2016-06-28 18:04


import json

from django.db import migrations


def fix_name(name):
    if '-' not in name:
        return name

    first, last = name.split('-')

    return first + '-' + last[0].upper() + last[1:]


def fix_goblin_names(apps, schema_editor):
    for person in apps.get_model("persons", "Person").objects.all().iterator():

        if person.race != 3:
            continue

        data = json.loads(person.data)

        data['name']['forms'] = [fix_name(form) for form in data['name']['forms']]


        person.data = json.dumps(data, ensure_ascii=True)
        person.save()


class Migration(migrations.Migration):

    dependencies = [
        ('persons', '0011_auto_20160424_0947'),
    ]

    operations = [
        migrations.RunPython(fix_goblin_names)
    ]
