# -*- coding: utf-8 -*-
# Generated by Django 1.9.1 on 2017-02-09 22:29
from __future__ import unicode_literals

from django.db import migrations, models

STR_TO_IDX = {
    'OE': 0,
    'YE': 1,
    'GE': 2,
    'RE': 3,
    'BL': 4,
    'GR': 5,
    'BK': 6,
    'PK': 7,
}

def migrate_color(apps, schema_editor):
    MyRoute = apps.get_model('boulders', 'Route')
    db_alias = schema_editor.connection.alias

    for route in MyRoute.objects.using(db_alias).all():
        route.color = STR_TO_IDX[route.color_old]
        route.save()

class Migration(migrations.Migration):

    dependencies = [
        ('boulders', '0001_initial'),
    ]

    operations = [
        migrations.RemoveField(
            model_name='route',
            name='climbers',
        ),
        migrations.AddField(
            model_name='climber',
            name='routes',
            field=models.ManyToManyField(through='boulders.Climb', to='boulders.Route'),
        ),
        migrations.AlterField(
            model_name='climber',
            name='gender',
            field=models.CharField(choices=[('m', 'Male'), ('f', 'Female')], max_length=1),
        ),
        migrations.AlterUniqueTogether('route', []),
        migrations.AlterIndexTogether('route', []),
        migrations.RenameField(
            model_name='route',
            old_name='color', new_name='color_old'
        ),
        migrations.AddField(
            model_name='route',
            name='color',
            field=models.PositiveSmallIntegerField(choices=[(0, 'Orange'), (1, 'Yellow'), (2, 'Green'), (3, 'Red'), (4, 'Blue'), (5, 'Gray'), (6, 'Black'), (7, 'Pink')], default=0),
        ),
        migrations.RunPython(migrate_color),
        migrations.RemoveField(
            model_name='route',
            name='color_old'
        ),
        migrations.AlterUniqueTogether('route', [('color','number')]),
        migrations.AlterIndexTogether('route', [('color', 'number')]),
    ]
