From d0c6449c39505de9098ddc3cdd8bc17bf30944ff Mon Sep 17 00:00:00 2001 From: mpeltriaux Date: Mon, 31 Jan 2022 10:52:35 +0100 Subject: [PATCH] # 88 Additional biotope codes * adds codelist 975 to project * adds new form field for adding extra biotope information --- .../management/commands/update_codelist.py | 3 +- codelist/settings.py | 1 + compensation/forms/modalForms.py | 19 ++++++++++- konova/autocompletes.py | 33 ++++++++++++++++++- konova/static/css/konova.css | 3 ++ konova/urls.py | 3 +- 6 files changed, 58 insertions(+), 4 deletions(-) diff --git a/codelist/management/commands/update_codelist.py b/codelist/management/commands/update_codelist.py index 5bb55b6a..aa6e45a9 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_BASE_URL, CODELIST_PROCESS_TYPE_ID + CODELIST_BASE_URL, CODELIST_PROCESS_TYPE_ID, CODELIST_BIOTOPES_EXTRA_CODES_ID from konova.management.commands.setup import BaseKonovaCommand from konova.settings import PROXIES @@ -33,6 +33,7 @@ class Command(BaseKonovaCommand): CODELIST_CONSERVATION_OFFICE_ID, CODELIST_REGISTRATION_OFFICE_ID, CODELIST_BIOTOPES_ID, + CODELIST_BIOTOPES_EXTRA_CODES_ID, CODELIST_LAW_ID, CODELIST_COMPENSATION_HANDLER_ID, CODELIST_COMPENSATION_ACTION_ID, diff --git a/codelist/settings.py b/codelist/settings.py index 15c523ac..012dc9b4 100644 --- a/codelist/settings.py +++ b/codelist/settings.py @@ -14,6 +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 = 974 # CL_EIV_Biotoptypen +CODELIST_BIOTOPES_EXTRA_CODES_ID = 975 # CLZusatzbezeichnung CODELIST_LAW_ID = 1048 # CLVerfahrensrecht CODELIST_PROCESS_TYPE_ID = 44382 # CLVerfahrenstyp diff --git a/compensation/forms/modalForms.py b/compensation/forms/modalForms.py index 885db951..53fdf3c2 100644 --- a/compensation/forms/modalForms.py +++ b/compensation/forms/modalForms.py @@ -14,7 +14,7 @@ from django.shortcuts import render from django.utils.translation import pgettext_lazy as _con, gettext_lazy as _ from codelist.models import KonovaCode -from codelist.settings import CODELIST_BIOTOPES_ID, CODELIST_COMPENSATION_ACTION_ID +from codelist.settings import CODELIST_BIOTOPES_ID, CODELIST_COMPENSATION_ACTION_ID, CODELIST_BIOTOPES_EXTRA_CODES_ID from compensation.models import CompensationDocument, EcoAccountDocument from konova.contexts import BaseContext from konova.forms import BaseModalForm, NewDocumentForm @@ -127,6 +127,23 @@ class NewStateModalForm(BaseModalForm): } ), ) + biotope_extra = forms.ModelChoiceField( + label=_("Biotope additional type"), + label_suffix="", + required=False, + help_text=_("Select an additional biotope type"), + queryset=KonovaCode.objects.filter( + is_archived=False, + is_leaf=True, + code_lists__in=[CODELIST_BIOTOPES_EXTRA_CODES_ID], + ), + widget=autocomplete.ModelSelect2Multiple( + url="codes-biotope-extra-type-autocomplete", + attrs={ + "data-placeholder": _("Biotope additional type"), + } + ), + ) surface = forms.DecimalField( min_value=0.00, decimal_places=2, diff --git a/konova/autocompletes.py b/konova/autocompletes.py index bee8dad8..cbe42b0c 100644 --- a/konova/autocompletes.py +++ b/konova/autocompletes.py @@ -11,7 +11,8 @@ 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_PROCESS_TYPE_ID + CODELIST_REGISTRATION_OFFICE_ID, CODELIST_CONSERVATION_OFFICE_ID, CODELIST_PROCESS_TYPE_ID, \ + CODELIST_BIOTOPES_EXTRA_CODES_ID from compensation.models import EcoAccount from intervention.models import Intervention @@ -192,6 +193,36 @@ class BiotopeCodeAutocomplete(KonovaCodeAutocomplete): return f"{result.long_name} ({result.short_name})" +class BiotopeExtraCodeAutocomplete(KonovaCodeAutocomplete): + """ + Due to limitations of the django dal package, we need to subclass for each code list + """ + group_by_related = "parent" + related_field_name = "long_name" + + def __init__(self, *args, **kwargs): + self.c = CODELIST_BIOTOPES_EXTRA_CODES_ID + super().__init__(*args, **kwargs) + + def order_by(self, qs): + """ Orders by a predefined value + + Wrapped in a function to provide inheritance-based different orders + + Args: + qs (QuerySet): The queryset to be ordered + + Returns: + qs (QuerySet): The ordered queryset + """ + return qs.order_by( + "parent__long_name", + ) + + def get_result_label(self, result): + return f"{result.long_name} ({result.short_name})" + + class LawCodeAutocomplete(KonovaCodeAutocomplete): """ Due to limitations of the django dal package, we need to subclass for each code list diff --git a/konova/static/css/konova.css b/konova/static/css/konova.css index 294287ea..a088cc30 100644 --- a/konova/static/css/konova.css +++ b/konova/static/css/konova.css @@ -229,4 +229,7 @@ No other approach worked to get the autocomplete fields to full width of parent } .select2-results__option--highlighted{ background-color: var(--rlp-red) !important; +} +.select2-container--default .select2-results > .select2-results__options{ + max-height: 500px !important; } \ No newline at end of file diff --git a/konova/urls.py b/konova/urls.py index 642b1445..96c716a8 100644 --- a/konova/urls.py +++ b/konova/urls.py @@ -20,7 +20,7 @@ from django.urls import path, include from konova.autocompletes import EcoAccountAutocomplete, \ InterventionAutocomplete, CompensationActionCodeAutocomplete, BiotopeCodeAutocomplete, LawCodeAutocomplete, \ RegistrationOfficeCodeAutocomplete, ConservationOfficeCodeAutocomplete, ProcessTypeCodeAutocomplete, \ - ShareUserAutocomplete + ShareUserAutocomplete, BiotopeExtraCodeAutocomplete from konova.settings import SSO_SERVER, SSO_PUBLIC_KEY, SSO_PRIVATE_KEY, DEBUG from konova.sso.sso import KonovaSSOClient from konova.views import logout_view, home_view, remove_deadline_view @@ -48,6 +48,7 @@ urlpatterns = [ path("atcmplt/interventions", InterventionAutocomplete.as_view(), name="interventions-autocomplete"), path("atcmplt/codes/comp/action", CompensationActionCodeAutocomplete.as_view(), name="codes-compensation-action-autocomplete"), path("atcmplt/codes/biotope", BiotopeCodeAutocomplete.as_view(), name="codes-biotope-autocomplete"), + path("atcmplt/codes/biotope/extra", BiotopeExtraCodeAutocomplete.as_view(), name="codes-biotope-extra-type-autocomplete"), path("atcmplt/codes/law", LawCodeAutocomplete.as_view(), name="codes-law-autocomplete"), path("atcmplt/codes/prc-type", ProcessTypeCodeAutocomplete.as_view(), name="codes-process-type-autocomplete"), path("atcmplt/codes/reg-off", RegistrationOfficeCodeAutocomplete.as_view(), name="codes-registration-office-autocomplete"),