# -*- coding: utf-8 -*-
# Generated by Django 1.10 on 2017-12-01 10:13
from __future__ import unicode_literals

from django.db import migrations


def add_issue_handler_group_type(apps, schema_editor):
    type_model = apps.get_model('user_group', 'UserGroupType')
    type_model.objects.get_or_create(name='issue_handler')


def remove_issue_handler_group_type(apps, schema_editor):
    type_model = apps.get_model('user_group', 'UserGroupType')
    type_model.objects.filter(name='issue_handler').delete()


def preset_issue_handler_group(apps, schema_editor):
    type_model = apps.get_model('user_group', 'UserGroupType')
    group_model = apps.get_model('user_group', 'UserGroup')
    app_model = apps.get_model('app', 'App')

    group_type = 'issue_handler'
    issue_handler_type = type_model.objects.get(name=group_type)
    for app in app_model.objects.all():
        group_model.objects.create(name=app.name + '_' + group_type, app=app,
                                   type=issue_handler_type, creator=app.creator)


class Migration(migrations.Migration):

    dependencies = [
        ('user_group', '0010_auto_20170804_2035'),
    ]

    operations = [
        migrations.RunPython(add_issue_handler_group_type, reverse_code=remove_issue_handler_group_type),
        migrations.RunPython(preset_issue_handler_group, reverse_code=migrations.RunPython.noop)
    ]

# -*- coding: utf-8 -*-
# Generated by Django 1.10 on 2017-12-01 10:13
from __future__ import unicode_literals

from django.db import migrations


def add_issue_handler_group_type(apps, schema_editor):
    type_model = apps.get_model('user_group', 'UserGroupType')
    type_model.objects.get_or_create(name='issue_handler')


def remove_issue_handler_group_type(apps, schema_editor):
    type_model = apps.get_model('user_group', 'UserGroupType')
    type_model.objects.filter(name='issue_handler').delete()


def preset_issue_handler_group(apps, schema_editor):
    type_model = apps.get_model('user_group', 'UserGroupType')
    group_model = apps.get_model('user_group', 'UserGroup')
    app_model = apps.get_model('app', 'App')

    group_type = 'issue_handler'
    issue_handler_type = type_model.objects.get(name=group_type)
    for app in app_model.objects.all():
        group_model.objects.create(name=app.name + '_' + group_type, app=app,
                                   type=issue_handler_type, creator=app.creator)


class Migration(migrations.Migration):

    dependencies = [
        ('user_group', '0010_auto_20170804_2035'),
    ]

    operations = [
        migrations.RunPython(add_issue_handler_group_type, reverse_code=remove_issue_handler_group_type),
        migrations.RunPython(preset_issue_handler_group, reverse_code=migrations.RunPython.noop)
    ]

# -*- coding: utf-8 -*- # Generated by Django 1.10 on 2017-12-01 10:13