<reponame>Buckinghamshire-Digital-Service/buckinghamshire-council
# Generated by Django 2.2.12 on 2020-05-20 09:51

from django.db import migrations

CHOICES = [
    ("CreateCase", "complaint"),
    ("CreateFOI", "foi"),
    ("CreateSAR", "sar"),
    ("CreateComments", "comments"),
    ("CreateCompliments", "compliments"),
    ("CreateDisclosures", "disclosures"),
]


def set_form_name_from_web_service_definition(apps, schema_editor):
    """Set a form value based on the web service name.

    This relies on the existing values (got from the API) being one of 

    - CreateCase
    - CreateComplaints
    - CreateSAR
    - CreateFOI
    - CreateComments
    - CreateCompliments
    - CreateDataBreach
    - CreateDisclosures"""

    FormPage = apps.get_model("cases", "ApteanRespondCaseFormPage")

    for page in FormPage.objects.all():
        for key, value in CHOICES:
            if key in page.web_service_definition:
                # key may be e.g. CreateFOI or TestCreateFOI
                page.form = value
                page.save()
                break


class Migration(migrations.Migration):

    dependencies = [
        ("cases", "0005_add_form_field"),
    ]

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

# Generated by Django 2.2.12 on 2020-05-20 09:51

from django.db import migrations

CHOICES = [
    ("CreateCase", "complaint"),
    ("CreateFOI", "foi"),
    ("CreateSAR", "sar"),
    ("CreateComments", "comments"),
    ("CreateCompliments", "compliments"),
    ("CreateDisclosures", "disclosures"),
]


def set_form_name_from_web_service_definition(apps, schema_editor):
    """Set a form value based on the web service name.

    This relies on the existing values (got from the API) being one of 

    - CreateCase
    - CreateComplaints
    - CreateSAR
    - CreateFOI
    - CreateComments
    - CreateCompliments
    - CreateDataBreach
    - CreateDisclosures"""

    FormPage = apps.get_model("cases", "ApteanRespondCaseFormPage")

    for page in FormPage.objects.all():
        for key, value in CHOICES:
            if key in page.web_service_definition:
                # key may be e.g. CreateFOI or TestCreateFOI
                page.form = value
                page.save()
                break


class Migration(migrations.Migration):

    dependencies = [
        ("cases", "0005_add_form_field"),
    ]

    operations = [
        migrations.RunPython(
            set_form_name_from_web_service_definition, migrations.RunPython.noop
        )
    ]
# Generated by Django 2.2.12 on 2020-05-20 09:51 Set a form value based on the web service name.      This relies on the existing values (got from the API) being one of       - CreateCase     - CreateComplaints     - CreateSAR     - CreateFOI     - CreateComments     - CreateCompliments     - CreateDataBreach     - CreateDisclosures # key may be e.g. CreateFOI or TestCreateFOI