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/models.py b/codelist/models.py
index fabb6f03..c455d1e1 100644
--- a/codelist/models.py
+++ b/codelist/models.py
@@ -57,6 +57,13 @@ class KonovaCode(models.Model):
ret_val += " ({})".format(self.short_name)
return ret_val
+ @property
+ def str_as_office(self):
+ ret_val = self.long_name
+ if self.parent:
+ ret_val += ", " + self.parent.long_name
+ return ret_val
+
class KonovaCodeList(models.Model):
"""
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/compensation/templates/compensation/detail/eco_account/view.html b/compensation/templates/compensation/detail/eco_account/view.html
index bd0fd48c..2c114e44 100644
--- a/compensation/templates/compensation/detail/eco_account/view.html
+++ b/compensation/templates/compensation/detail/eco_account/view.html
@@ -52,9 +52,9 @@
{% endif %}
-
+
{% trans 'Conservation office' %} |
- {{obj.responsible.conservation_office|default_if_none:""}} |
+ {{obj.responsible.conservation_office.str_as_office|default_if_none:""}} |
{% trans 'Conversation office file number' %} |
diff --git a/ema/templates/ema/detail/view.html b/ema/templates/ema/detail/view.html
index 561e2d63..9ffce728 100644
--- a/ema/templates/ema/detail/view.html
+++ b/ema/templates/ema/detail/view.html
@@ -38,9 +38,9 @@
{% endif %}
-
+
{% trans 'Conservation office' %} |
- {{obj.responsible.conservation_office|default_if_none:""}} |
+ {{obj.responsible.conservation_office.str_as_office|default_if_none:""}} |
{% trans 'Conversation office file number' %} |
diff --git a/intervention/models.py b/intervention/models.py
index c583784f..a62da795 100644
--- a/intervention/models.py
+++ b/intervention/models.py
@@ -10,6 +10,9 @@ from django.contrib.gis.db import models
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, 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
@@ -23,11 +26,33 @@ class ResponsibilityData(UuidModel):
Holds intervention data about responsible organizations and their file numbers for this case
"""
- registration_office = models.ForeignKey(Organisation, on_delete=models.SET_NULL, null=True, related_name="+", blank=True)
+ registration_office = models.ForeignKey(
+ KonovaCode,
+ on_delete=models.SET_NULL,
+ null=True,
+ related_name="+",
+ blank=True,
+ limit_choices_to={
+ "code_lists__in": [CODELIST_REGISTRATION_OFFICE_ID],
+ "is_selectable": True,
+ "is_archived": False,
+ }
+ )
registration_file_number = models.CharField(max_length=1000, blank=True, null=True)
- conservation_office = models.ForeignKey(Organisation, on_delete=models.SET_NULL, null=True, related_name="+", blank=True)
+ conservation_office = models.ForeignKey(
+ KonovaCode,
+ on_delete=models.SET_NULL,
+ null=True,
+ related_name="+",
+ blank=True,
+ limit_choices_to={
+ "code_lists__in": [CODELIST_CONSERVATION_OFFICE_ID],
+ "is_selectable": True,
+ "is_archived": False,
+ }
+ )
conservation_file_number = models.CharField(max_length=1000, blank=True, null=True)
- handler = models.CharField(max_length=500, null=True, blank=True, help_text="Refers to 'Eingriffsverursacher'")
+ handler = models.CharField(max_length=500, null=True, blank=True, help_text="Refers to 'Eingriffsverursacher' or 'Maßnahmenträger'")
def __str__(self):
return "ZB: {} | ETS: {} | Handler: {}".format(
@@ -62,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/intervention/templates/intervention/detail/view.html b/intervention/templates/intervention/detail/view.html
index 4bfc27aa..8c6c0954 100644
--- a/intervention/templates/intervention/detail/view.html
+++ b/intervention/templates/intervention/detail/view.html
@@ -38,17 +38,17 @@
{% trans 'Law' %} |
{{intervention.legal.law|default_if_none:""}} |
-
+
{% trans 'Registration office' %} |
- {{intervention.responsible.registration_office|default_if_none:""}} |
+ {{intervention.responsible.registration_office.str_as_office|default_if_none:""}} |
{% trans 'Registration office file number' %} |
{{intervention.responsible.registration_file_number|default_if_none:""}} |
-
+
{% trans 'Conservation office' %} |
- {{intervention.responsible.conservation_office|default_if_none:""}} |
+ {{intervention.responsible.conservation_office.str_as_office|default_if_none:""}} |
{% trans 'Conversation office file number' %} |
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