From 8224f4c8c5bc45bb95e815e87d718166ccef089a Mon Sep 17 00:00:00 2001 From: mpeltriaux Date: Wed, 16 Feb 2022 09:08:11 +0100 Subject: [PATCH] # 110 Biotope codes * removes list 974 from update_codelist.py command * adds migration for existing biotope states to be changed into proper list --- .../management/commands/update_codelist.py | 3 +- codelist/settings.py | 2 +- konova/migrations/0005_auto_20220216_0856.py | 40 +++++++++++++++++++ 3 files changed, 42 insertions(+), 3 deletions(-) create mode 100644 konova/migrations/0005_auto_20220216_0856.py diff --git a/codelist/management/commands/update_codelist.py b/codelist/management/commands/update_codelist.py index 3fd4c6c3..85c90324 100644 --- a/codelist/management/commands/update_codelist.py +++ b/codelist/management/commands/update_codelist.py @@ -14,7 +14,7 @@ from codelist.settings import CODELIST_INTERVENTION_HANDLER_ID, CODELIST_CONSERV CODELIST_REGISTRATION_OFFICE_ID, CODELIST_BIOTOPES_ID, CODELIST_LAW_ID, CODELIST_COMPENSATION_HANDLER_ID, \ CODELIST_COMPENSATION_ACTION_ID, CODELIST_COMPENSATION_ACTION_CLASS_ID, CODELIST_COMPENSATION_ADDITIONAL_TYPE_ID, \ CODELIST_BASE_URL, CODELIST_PROCESS_TYPE_ID, CODELIST_BIOTOPES_EXTRA_CODES_ID, \ - CODELIST_COMPENSATION_ACTION_DETAIL_ID, CODELIST_AFTER_STATE_BIOTOPES__ID + CODELIST_COMPENSATION_ACTION_DETAIL_ID from konova.management.commands.setup import BaseKonovaCommand from konova.settings import PROXIES @@ -34,7 +34,6 @@ class Command(BaseKonovaCommand): CODELIST_CONSERVATION_OFFICE_ID, CODELIST_REGISTRATION_OFFICE_ID, CODELIST_BIOTOPES_ID, - CODELIST_AFTER_STATE_BIOTOPES__ID, CODELIST_BIOTOPES_EXTRA_CODES_ID, CODELIST_LAW_ID, CODELIST_COMPENSATION_HANDLER_ID, diff --git a/codelist/settings.py b/codelist/settings.py index 53cef730..b4226b5e 100644 --- a/codelist/settings.py +++ b/codelist/settings.py @@ -14,7 +14,7 @@ CODELIST_INTERVENTION_HANDLER_ID = 903 # CLMassnahmeträger CODELIST_CONSERVATION_OFFICE_ID = 907 # CLNaturschutzbehörden CODELIST_REGISTRATION_OFFICE_ID = 1053 # CLZulassungsbehörden CODELIST_BIOTOPES_ID = 654 # CL_Biotoptypen -CODELIST_AFTER_STATE_BIOTOPES__ID = 974 # CL-KSP_ZielBiotoptypen +CODELIST_AFTER_STATE_BIOTOPES__ID = 974 # CL-KSP_ZielBiotoptypen - USAGE HAS BEEN DROPPED IN 2022 IN FAVOR OF 654 CODELIST_BIOTOPES_EXTRA_CODES_ID = 975 # CLZusatzbezeichnung CODELIST_LAW_ID = 1048 # CLVerfahrensrecht CODELIST_PROCESS_TYPE_ID = 44382 # CLVerfahrenstyp diff --git a/konova/migrations/0005_auto_20220216_0856.py b/konova/migrations/0005_auto_20220216_0856.py new file mode 100644 index 00000000..43c518ae --- /dev/null +++ b/konova/migrations/0005_auto_20220216_0856.py @@ -0,0 +1,40 @@ +# Generated by Django 3.1.3 on 2022-02-16 07:56 + +from django.db import migrations, transaction + +from codelist.settings import CODELIST_BIOTOPES_ID, CODELIST_AFTER_STATE_BIOTOPES__ID + + +def migrate_biotopes_from_974_to_654(apps, schema_editor): + KonovaCode = apps.get_model("codelist", "KonovaCode") + CompensationState = apps.get_model("compensation", "CompensationState") + all_states = CompensationState.objects.all() + + with transaction.atomic(): + for state in all_states: + new_biotope_code = KonovaCode.objects.get( + code_lists__in=[CODELIST_BIOTOPES_ID], + is_selectable=True, + is_archived=False, + short_name=state.biotope_type.short_name, + ) + state.biotope_type = new_biotope_code + state.save() + + all_states = CompensationState.objects.all() + after_state_list_elements = all_states.filter( + biotope_type__code_lists__in=[CODELIST_AFTER_STATE_BIOTOPES__ID] + ) + if after_state_list_elements.count() > 0: + raise Exception("Still states with wrong codelist entries!") + + +class Migration(migrations.Migration): + + dependencies = [ + ('konova', '0004_auto_20220209_0839'), + ] + + operations = [ + migrations.RunPython(migrate_biotopes_from_974_to_654), + ]