# Generated by Django 1.11.8 on 2018-02-24 21:14

from django.db import migrations


def init_templates(apps, schema_editor):
    from byro.mails import default

    MailTemplate = apps.get_model("mails", "MailTemplate")
    Configuration = apps.get_model("common", "Configuration")
    config, _ = Configuration.objects.get_or_create()
    if not config.leave_member_template:
        leave_member = MailTemplate.objects.create(
            subject=default.LEAVE_MEMBER_SUBJECT, text=default.LEAVE_MEMBER_TEXT
        )
        config.leave_member_template = leave_member
    if not config.leave_office_template:
        leave_office = MailTemplate.objects.create(
            subject=default.LEAVE_MEMBER_OFFICE_SUBJECT,
            text=default.LEAVE_MEMBER_OFFICE_TEXT,
        )
        config.leave_office_template = leave_office
    config.save()


class Migration(migrations.Migration):
    dependencies = [("common", "0008_configuration_backoffice_mail")]

    operations = [migrations.RunPython(init_templates, migrations.RunPython.noop)]
