# -*- coding: utf-8 -*-
# Generated by Django 1.10.5 on 2017-05-30 11:54
from __future__ import unicode_literals

from django.db import migrations
from django.contrib.auth.models import Group, User, Permission


def load_coordinator_group(apps, schema_editor):
	group, created = Group.objects.get_or_create(name='Coordinator')

	company_permissions = Permission.objects.filter(
		content_type__app_label='company'
	).exclude(
		codename__startswith='add', 
		content_type__model__in=['company', 'job'],
	).exclude(
		codename__startswith='delete',
		content_type__model__in=['company', 'branch', 'job'],
	)

	consent_permissions = Permission.objects.filter(codename='change_consentdeadline')

	for p in company_permissions:
		group.permissions.add(p)
	
	for p in consent_permissions:
		group.permissions.add(p)


class Migration(migrations.Migration):

    dependencies = [
        ('company', '0016_auto_20170529_2226'),
    ]

    operations = [
    	migrations.RunPython(load_coordinator_group),
    ]
