# Generated by Django 3.1.2 on 2021-01-27 18:43

from django.db import migrations


class Migration(migrations.Migration):
    def add_file_data_providers(apps, schema_editor):
        DataProviderType = apps.get_model("jobs", "DataProviderType")
        ExportFormat = apps.get_model("jobs", "ExportFormat")

        # Create the DataProvider objects if they don't exist.
        DataProviderType.objects.get_or_create(type_name="vector-file")
        DataProviderType.objects.get_or_create(type_name="raster-file")

        # Currently available Provider Types.
        vector_data_provider_types = ["vector-file"]
        raster_data_provider_types = ["raster-file"]

        # Currently available Export Formats.
        nitf = ExportFormat.objects.get(slug="nitf")
        gtiff = ExportFormat.objects.get(slug="gtiff")
        kml = ExportFormat.objects.get(slug="kml")
        shp = ExportFormat.objects.get(slug="shp")
        gpkg = ExportFormat.objects.get(slug="gpkg")

        # Set the known supported export formats per provider type.
        for provider_type in DataProviderType.objects.all():
            if provider_type.type_name in vector_data_provider_types:
                provider_type.supported_formats.add(gpkg, shp, kml)
            if provider_type.type_name in raster_data_provider_types:
                provider_type.supported_formats.add(gpkg, gtiff, nitf)

    dependencies = [
        ("jobs", "0010_dataprovider_data_type"),
    ]

    operations = [migrations.RunPython(add_file_data_providers)]

# Generated by Django 3.1.2 on 2021-01-27 18:43

from django.db import migrations


class Migration(migrations.Migration):
    def add_file_data_providers(apps, schema_editor):
        DataProviderType = apps.get_model("jobs", "DataProviderType")
        ExportFormat = apps.get_model("jobs", "ExportFormat")

        # Create the DataProvider objects if they don't exist.
        DataProviderType.objects.get_or_create(type_name="vector-file")
        DataProviderType.objects.get_or_create(type_name="raster-file")

        # Currently available Provider Types.
        vector_data_provider_types = ["vector-file"]
        raster_data_provider_types = ["raster-file"]

        # Currently available Export Formats.
        nitf = ExportFormat.objects.get(slug="nitf")
        gtiff = ExportFormat.objects.get(slug="gtiff")
        kml = ExportFormat.objects.get(slug="kml")
        shp = ExportFormat.objects.get(slug="shp")
        gpkg = ExportFormat.objects.get(slug="gpkg")

        # Set the known supported export formats per provider type.
        for provider_type in DataProviderType.objects.all():
            if provider_type.type_name in vector_data_provider_types:
                provider_type.supported_formats.add(gpkg, shp, kml)
            if provider_type.type_name in raster_data_provider_types:
                provider_type.supported_formats.add(gpkg, gtiff, nitf)

    dependencies = [
        ("jobs", "0010_dataprovider_data_type"),
    ]

    operations = [migrations.RunPython(add_file_data_providers)]

# Generated by Django 3.1.2 on 2021-01-27 18:43 # Create the DataProvider objects if they don't exist. # Currently available Provider Types. # Currently available Export Formats. # Set the known supported export formats per provider type.