# -*- coding: utf-8 -*-
# Generated by Django 1.9.6 on 2016-05-20 02:26
from __future__ import unicode_literals

from django.db import migrations

from dartcms.apps.modules.models import Module, ModuleGroup

MODULE_GROUPS = [
    {
        'sort': 1,
        'description': '',
        'fa': 'fa-flag',
        'slug': 'admin',
        'name': 'Administration',
        'modules': [
            {
                'sort': 1,
                'is_enabled': True,
                'name': 'CMS Users',
                'slug': 'cms-users',
                'description': ''
            }
        ]
    },
    {
        'sort': 2,
        'description': '',
        'fa': 'fa-file',
        'slug': 'content',
        'name': 'Content',
        'modules': [
            {
                'sort': 1,
                'is_enabled': True,
                'name': 'Site Structure',
                'slug': 'sitemap',
                'description': ''
            },
            {
                'sort': 2,
                'is_enabled': True,
                'name': 'Feeds',
                'slug': 'feeds',
                'description': ''
            }
        ]
    },
    {
        'sort': 3,
        'description': '',
        'fa': 'fa-cog',
        'slug': 'service',
        'name': 'Services',
        'modules': [
            {
                'sort': 1,
                'is_enabled': True,
                'name': 'Contacts',
                'slug': 'contacts',
                'description': ''
            }
        ]
    }
]


def insert_modules(apps, schema):
    for group in MODULE_GROUPS:
        group_modules = group.pop('modules', [])
        group = ModuleGroup.objects.create(**group)
        for module in group_modules:
            module['group'] = group
            Module.objects.create(**module)


def delete_modules(apps, schema):
    for group in MODULE_GROUPS:
        ModuleGroup.objects.get(slug=group['slug']).delete()


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

    operations = [
        migrations.RunPython(insert_modules, delete_modules)
    ]
