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

from django.db import migrations, models


def move_needs_approval(apps, schema_editor):
    Workshop = apps.get_model("workshops", "Workshop")
    db_alias = schema_editor.connection.alias
    for workshop in Workshop.objects.using(db_alias).all():
        activity = workshop.trainingactivity_ptr
        activity.needs_approval = workshop.needs_approval
        activity.save(using=db_alias)


def move_needs_approval_reverse(apps, schema_editor):
    Workshop = apps.get_model("workshops", "Workshop")
    db_alias = schema_editor.connection.alias
    for workshop in Workshop.objects.using(db_alias).all():
        activity = workshop.trainingactivity_ptr
        workshop.needs_approval = activity.needs_approval
        workshop.save(using=db_alias)


class Migration(migrations.Migration):

    dependencies = [
        ('trainings', '0027_merge'),
        ('workshops', '0024_auto_20150928_1552'),
    ]

    operations = [
        migrations.AddField(
            model_name='trainingactivity',
            name='needs_approval',
            field=models.BooleanField(default=False, help_text='Does the activity needs a trainer approval to be started?', verbose_name='needs trainer approval'),
        ),
        migrations.RunPython(
            move_needs_approval,
            move_needs_approval_reverse
        )
    ]
