From 81cea4f045d736633ef0b7148dd19c63e7ff0a33 Mon Sep 17 00:00:00 2001 From: mipel Date: Fri, 27 Aug 2021 15:16:05 +0200 Subject: [PATCH] [Compensation] Conservation office #5 * keeps responsible data in compensation model for potential future purposes * refactors registration_office and conservation_office to map onto KonovaCodes instead of own Organization model * adds str_as_office property-method to KonovaCode to provide an easy way of rendering template data * adds missing highlighting in case of missing information about registration office and conservation office * extends KonovaCode command update_codelist.py for CODELIST_PROCESS_TYPE_ID * adds preselectors for konova codes in models of CompensationAction, Law and CompensationState --- .../management/commands/update_codelist.py | 4 ++- codelist/settings.py | 3 +- compensation/models.py | 15 ++++++++-- intervention/models.py | 29 +++++++++++++++++-- konova/autocompletes.py | 11 ++++++- 5 files changed, 54 insertions(+), 8 deletions(-) diff --git a/codelist/management/commands/update_codelist.py b/codelist/management/commands/update_codelist.py index 808d1ed9..cd9abe1c 100644 --- a/codelist/management/commands/update_codelist.py +++ b/codelist/management/commands/update_codelist.py @@ -13,7 +13,7 @@ from codelist.models import KonovaCode, KonovaCodeList from codelist.settings import CODELIST_INTERVENTION_HANDLER_ID, CODELIST_CONSERVATION_OFFICE_ID, \ 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_COMPENSATION_COMBINATION_ID, CODELIST_BASE_URL + CODELIST_COMPENSATION_COMBINATION_ID, CODELIST_BASE_URL, CODELIST_PROCESS_TYPE_ID bool_map = { "true": True, @@ -36,6 +36,7 @@ class Command(BaseCommand): CODELIST_COMPENSATION_ACTION_CLASS_ID, CODELIST_COMPENSATION_ADDITIONAL_TYPE_ID, CODELIST_COMPENSATION_COMBINATION_ID, + CODELIST_PROCESS_TYPE_ID, ] self._write_warning("Fetching codes...") @@ -69,6 +70,7 @@ class Command(BaseCommand): if items is None: return else: + self._write_warning(" --- Found {} subcodes. Process now...".format(len(items))) for element in items: children = element.find("items") _id = element.find("id").text diff --git a/codelist/settings.py b/codelist/settings.py index c309b7a8..e2548b41 100644 --- a/codelist/settings.py +++ b/codelist/settings.py @@ -15,9 +15,10 @@ CODELIST_CONSERVATION_OFFICE_ID = 907 # CLNaturschutzbehörden CODELIST_REGISTRATION_OFFICE_ID = 1053 # CLZulassungsbehörden CODELIST_BIOTOPES_ID = 974 # CL_EIV_Biotoptypen CODELIST_LAW_ID = 1048 # CLVerfahrensrecht +CODELIST_PROCESS_TYPE_ID = 44382 # CLVerfahrenstyp CODELIST_COMPENSATION_HANDLER_ID = 1052 # CLEingreifer CODELIST_COMPENSATION_ACTION_ID = 1026 # CLMassnahmedetail CODELIST_COMPENSATION_ACTION_CLASS_ID = 1034 # CLMassnahmeklasse -CODELIST_COMPENSATION_ADDITIONAL_TYPE_ID = 1028 # CLMassnahmetyp +CODELIST_COMPENSATION_ADDITIONAL_TYPE_ID = 1028 # CLMassnahmetyp, CEF and stuff CODELIST_COMPENSATION_COMBINATION_ID = 1049 # CLKombimassnahme diff --git a/compensation/models.py b/compensation/models.py index 6f05ba53..c54d44fa 100644 --- a/compensation/models.py +++ b/compensation/models.py @@ -12,6 +12,7 @@ from django.db.models import Sum from django.utils.translation import gettext_lazy as _ from codelist.models import KonovaCode +from codelist.settings import CODELIST_COMPENSATION_ACTION_ID, CODELIST_BIOTOPES_ID from intervention.models import Intervention, ResponsibilityData from konova.models import BaseObject, BaseResource, Geometry, UuidModel from konova.settings import DEFAULT_SRID_RLP, LANIS_LINK_TEMPLATE @@ -52,7 +53,12 @@ class CompensationState(UuidModel): KonovaCode, on_delete=models.SET_NULL, null=True, - blank=True + blank=True, + limit_choices_to={ + "code_lists__in": [CODELIST_BIOTOPES_ID], + "is_selectable": True, + "is_archived": False, + } ) surface = models.FloatField() @@ -80,7 +86,12 @@ class CompensationAction(BaseResource): KonovaCode, on_delete=models.SET_NULL, null=True, - blank=True + blank=True, + limit_choices_to={ + "code_lists__in": [CODELIST_COMPENSATION_ACTION_ID], + "is_selectable": True, + "is_archived": False, + } ) amount = models.FloatField() unit = models.CharField(max_length=100, null=True, blank=True, choices=UnitChoices.choices) diff --git a/intervention/models.py b/intervention/models.py index 202b726f..a62da795 100644 --- a/intervention/models.py +++ b/intervention/models.py @@ -11,7 +11,8 @@ from django.utils.timezone import localtime from django.utils.translation import gettext_lazy as _ from codelist.models import KonovaCode -from codelist.settings import CODELIST_REGISTRATION_OFFICE_ID, CODELIST_CONSERVATION_OFFICE_ID +from codelist.settings import CODELIST_REGISTRATION_OFFICE_ID, CODELIST_CONSERVATION_OFFICE_ID, CODELIST_LAW_ID, \ + CODELIST_PROCESS_TYPE_ID from konova.models import BaseObject, Geometry, UuidModel, BaseResource from konova.settings import DEFAULT_SRID_RLP, LANIS_LINK_TEMPLATE from konova.sub_settings.django_settings import DEFAULT_DATE_TIME_FORMAT @@ -86,8 +87,30 @@ class LegalData(UuidModel): # Refers to "Bestandskraft am" binding_date = models.DateField(null=True, blank=True, help_text="Refers to 'Bestandskraft am'") - process_type = models.CharField(max_length=500, null=True, blank=True) - law = models.CharField(max_length=500, null=True, blank=True) + process_type = models.ForeignKey( + KonovaCode, + on_delete=models.SET_NULL, + null=True, + related_name="+", + blank=True, + limit_choices_to={ + "code_lists__in": [CODELIST_PROCESS_TYPE_ID], + "is_selectable": True, + "is_archived": False, + } + ) + law = models.ForeignKey( + KonovaCode, + on_delete=models.SET_NULL, + null=True, + related_name="+", + blank=True, + limit_choices_to={ + "code_lists__in": [CODELIST_LAW_ID], + "is_selectable": True, + "is_archived": False, + } + ) revocation = models.ForeignKey(Revocation, null=True, blank=True, help_text="Refers to 'Widerspruch am'", on_delete=models.SET_NULL) diff --git a/konova/autocompletes.py b/konova/autocompletes.py index 227b5923..a75a711a 100644 --- a/konova/autocompletes.py +++ b/konova/autocompletes.py @@ -10,7 +10,7 @@ from django.db.models import Q from codelist.models import KonovaCode from codelist.settings import CODELIST_COMPENSATION_ACTION_ID, CODELIST_BIOTOPES_ID, CODELIST_LAW_ID, \ - CODELIST_REGISTRATION_OFFICE_ID, CODELIST_CONSERVATION_OFFICE_ID + CODELIST_REGISTRATION_OFFICE_ID, CODELIST_CONSERVATION_OFFICE_ID, CODELIST_PROCESS_TYPE_ID from compensation.models import EcoAccount from intervention.models import Intervention from organisation.models import Organisation @@ -138,6 +138,15 @@ class LawCodeAutocomplete(KonovaCodeAutocomplete): super().__init__(*args, **kwargs) +class ProcessTypeCodeAutocomplete(KonovaCodeAutocomplete): + """ + Due to limitations of the django dal package, we need to subclass for each code list + """ + def __init__(self, *args, **kwargs): + self.c = CODELIST_PROCESS_TYPE_ID + super().__init__(*args, **kwargs) + + class RegistrationOfficeCodeAutocomplete(KonovaCodeAutocomplete): """ Due to limitations of the django dal package, we need to subclass for each code list