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/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..202b726f 100644 --- a/intervention/models.py +++ b/intervention/models.py @@ -10,6 +10,8 @@ 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 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 +25,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( 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' %}