# -*- coding: utf-8 -*-
# Generated by Django 1.11.12 on 2018-04-16 15:33
from __future__ import unicode_literals

from django.db import migrations

from branding.utils import get_or_create_organization


def create_default_organization(apps, schema_editor):
    """Assign a default primary domain for each org"""
    Organization = apps.get_model('branding', 'Organization')
    Domain = apps.get_model('branding', 'Domain')
    EmailWrapper = apps.get_model('mailer', 'EmailWrapper')
    OrganizationElection = apps.get_model('election', 'OrganizationElection')
    Election = apps.get_model('election', 'Election')

    org, _ = get_or_create_organization(name='Default',
                                        platform_name='Voting System',
                                        hostname='testserver',
                                        homepage='http://localhost',
                                        organization_model=Organization,
                                        domain_model=Domain,
                                        emailwrapper_model=EmailWrapper,
                                        orgelection_model=OrganizationElection,
                                        election_model=Election)

    Domain.objects.get_or_create(hostname='localhost', organization=org)



class Migration(migrations.Migration):

    dependencies = [
        ('branding', '0003_foreign_relationships_mailer'),
        ('mailer', '0004_sending_address'),
        ('election', '0003_load_data'),
    ]

    operations = [
        migrations.RunPython(create_default_organization, lambda x,y: None)
    ]
