@@ -0,0 +1,2271 @@
+from django.conf import settings%0Afrom django.db import migrations%0A%0Afrom adhocracy4.dashboard.blueprints import get_blueprints%0Afrom meinberlin.apps.bplan.views import BplanProjectCreateView%0Afrom meinberlin.apps.extprojects.views import ExternalProjectCreateView%0Afrom meinberlin.apps.projectcontainers.views import ContainerCreateView%0A%0A%0Adef determine_and_add_blueprint_types_to_modules(apps, schema_editor):%0A    %22%22%22Determine the blueprint type of existing modules by their phase set%0A    and add accordingly.%0A%0A    Run this migration after types have been added to blueprints and%0A    'A4_BLUEPRINT_TYPES have been added to settings.'%0A    %22%22%22%0A    if hasattr(settings, 'A4_BLUEPRINT_TYPES'):%0A        blueprints = %5Bblueprint%5B1%5D for blueprint in get_blueprints()%5D%0A        blueprints.append(BplanProjectCreateView.blueprint)%0A        blueprints.append(ExternalProjectCreateView.blueprint)%0A        blueprints.append(ContainerCreateView.blueprint)%0A%0A        # create dictionary with concatenated phase identifiers as keys%0A        # and type as values%0A        phase_identifiers_to_blueprint_type = %7B%0A            '-'.join(%5Bphase.identifier for phase in blueprint.content%5D):%0A                blueprint.type%0A            for blueprint in blueprints%0A        %7D%0A%0A        Module = apps.get_model('a4modules', 'Module')%0A        for module in Module.objects.all():%0A            phase_identifiers_str = %5C%0A                '-'.join(%5Bphase.type for phase in module.phase_set.all()%5D)%0A            if phase_identifiers_str in phase_identifiers_to_blueprint_type %5C%0A               and not module.blueprint_type:%0A                module.blueprint_type = %5C%0A                    phase_identifiers_to_blueprint_type%5Bphase_identifiers_str%5D%0A                module.save()%0A%0A%0Adef remove_blueprint_types(apps, schema_editor):%0A    Module = apps.get_model('a4modules', 'Module')%0A    for module in Module.objects.all():%0A        module.blueprint_type = ''%0A        module.save()%0A%0A%0Aclass Migration(migrations.Migration):%0A%0A    dependencies = %5B%0A        ('meinberlin_projects', '0002_custom_project_types'),%0A        ('a4modules', '0006_module_blueprint_type'),%0A    %5D%0A%0A    operations = %5B%0A        migrations.RunPython(%0A            determine_and_add_blueprint_types_to_modules,%0A            remove_blueprint_types%0A        ),%0A    %5D%0A

add migration to determine and add blueprint types to existing modules