Compensation action code list

* integrates action code list to NewActionForm
This commit is contained in:
mipel
2021-08-24 09:31:12 +02:00
parent 41c9ed106c
commit e9aea7bcc4
4 changed files with 37 additions and 11 deletions

View File

@@ -8,6 +8,7 @@ Created on: 07.12.20
from dal_select2.views import Select2QuerySetView
from codelist.models import KonovaCode
from codelist.settings import CODELIST_COMPENSATION_ACTION_ID, CODELIST_BIOTOPES_ID
from compensation.models import EcoAccount
from intervention.models import Intervention
from organisation.models import Organisation
@@ -86,17 +87,12 @@ class KonovaCodeAutocomplete(Select2QuerySetView):
* c: Search inside a special codelist
"""
def dispatch(self, request, *args, **kwargs):
# Retrieve 'c' for 'code' from request
self.c = request.GET.get("c", "")
return super().dispatch(request, *args, **kwargs)
def get_queryset(self):
if self.request.user.is_anonymous:
return KonovaCode.objects.none()
qs = KonovaCode.objects.filter(
is_active=True,
is_leaf=True,
parent__isnull=False,
)
if self.c:
qs = qs.filter(
@@ -109,4 +105,22 @@ class KonovaCodeAutocomplete(Select2QuerySetView):
qs.order_by(
"long_name"
)
return qs
return qs
class CompensationActionCodeAutocomplete(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_COMPENSATION_ACTION_ID
super().__init__(*args, **kwargs)
class BiotopeCodeAutocomplete(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_BIOTOPES_ID
super().__init__(*args, **kwargs)

View File

@@ -18,7 +18,7 @@ from django.contrib import admin
from django.urls import path, include
from konova.autocompletes import OrganisationAutocomplete, NonOfficialOrganisationAutocomplete, EcoAccountAutocomplete, \
InterventionAutocomplete, KonovaCodeAutocomplete
InterventionAutocomplete, CompensationActionCodeAutocomplete
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, get_document_view, remove_document_view, remove_deadline_view
@@ -49,7 +49,7 @@ urlpatterns = [
path("atcmplt/orgs/other", NonOfficialOrganisationAutocomplete.as_view(), name="other-orgs-autocomplete"),
path("atcmplt/eco-accounts", EcoAccountAutocomplete.as_view(), name="accounts-autocomplete"),
path("atcmplt/interventions", InterventionAutocomplete.as_view(), name="interventions-autocomplete"),
path("atcmplt/codes", KonovaCodeAutocomplete.as_view(), name="codes-autocomplete"),
path("atcmplt/codes/compensation-action", CompensationActionCodeAutocomplete.as_view(), name="codes-compensation-action-autocomplete"),
]
if DEBUG: