# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import models, migrations

from users.models import HEAD_OF_LAB_ID, QUALITY_MANAGER_ID


def downgrade_user(apps, schema_editor):
    from django.db.transaction import atomic

    with atomic():
        newmodel = apps.get_model('users', 'WinoseUser')
        for u in newmodel.objects.all():
            # existing quality manager users get 'downgraded' to
            # just head of olf
            if u.user_group == 'Z':
                u.user_group = HEAD_OF_LAB_ID
                u.save()


class Migration(migrations.Migration):
    dependencies = [
        ('users', '0001_initial'),
    ]

    operations = [
        migrations.AlterField(
            model_name='winoseuser',
            name='user_group',
            field=models.CharField(blank=True, max_length=1,
                                   choices=[('A', 'lab technician'), ('L', 'head of olfactometry')]),
            preserve_default=True,
        ),
        migrations.RunPython(
            downgrade_user,
        )
    ]
