Compensation action code list
* integrates action code list to NewActionForm
This commit is contained in:
parent
41c9ed106c
commit
e9aea7bcc4
@ -41,7 +41,7 @@ class KonovaCode(models.Model):
|
|||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
if self.is_leaf and self.parent:
|
if self.is_leaf and self.parent:
|
||||||
return "{} | {}".format(self.parent.long_name, self.long_name)
|
return "{} > {}".format(self.parent.long_name, self.long_name)
|
||||||
return self.long_name
|
return self.long_name
|
||||||
|
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@ Created on: 04.12.20
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
from bootstrap_modal_forms.utils import is_ajax
|
from bootstrap_modal_forms.utils import is_ajax
|
||||||
|
from dal import autocomplete
|
||||||
from django import forms
|
from django import forms
|
||||||
from django.contrib import messages
|
from django.contrib import messages
|
||||||
from django.db import transaction
|
from django.db import transaction
|
||||||
@ -13,6 +14,7 @@ from django.http import HttpRequest, HttpResponseRedirect
|
|||||||
from django.shortcuts import render
|
from django.shortcuts import render
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
|
||||||
|
from codelist.models import KonovaCode
|
||||||
from compensation.models import Payment, CompensationState, CompensationAction, UnitChoices
|
from compensation.models import Payment, CompensationState, CompensationAction, UnitChoices
|
||||||
from konova.contexts import BaseContext
|
from konova.contexts import BaseContext
|
||||||
from konova.forms import BaseForm, BaseModalForm
|
from konova.forms import BaseForm, BaseModalForm
|
||||||
@ -256,11 +258,21 @@ class NewDeadlineModalForm(BaseModalForm):
|
|||||||
|
|
||||||
|
|
||||||
class NewActionModalForm(BaseModalForm):
|
class NewActionModalForm(BaseModalForm):
|
||||||
action_type = forms.CharField(
|
action_type = forms.ModelChoiceField(
|
||||||
label=_("Action Type"),
|
label=_("Action Type"),
|
||||||
label_suffix="",
|
label_suffix="",
|
||||||
required=True,
|
required=True,
|
||||||
help_text=_("Select the action type"),
|
help_text=_("Select the action type"),
|
||||||
|
queryset=KonovaCode.objects.filter(
|
||||||
|
is_active=True,
|
||||||
|
),
|
||||||
|
widget=autocomplete.ModelSelect2(
|
||||||
|
url="codes-compensation-action-autocomplete",
|
||||||
|
attrs={
|
||||||
|
"data-placeholder": _("Action"),
|
||||||
|
"data-minimum-input-length": 3,
|
||||||
|
}
|
||||||
|
),
|
||||||
)
|
)
|
||||||
unit = forms.ChoiceField(
|
unit = forms.ChoiceField(
|
||||||
label=_("Unit"),
|
label=_("Unit"),
|
||||||
|
@ -8,6 +8,7 @@ Created on: 07.12.20
|
|||||||
from dal_select2.views import Select2QuerySetView
|
from dal_select2.views import Select2QuerySetView
|
||||||
|
|
||||||
from codelist.models import KonovaCode
|
from codelist.models import KonovaCode
|
||||||
|
from codelist.settings import CODELIST_COMPENSATION_ACTION_ID, CODELIST_BIOTOPES_ID
|
||||||
from compensation.models import EcoAccount
|
from compensation.models import EcoAccount
|
||||||
from intervention.models import Intervention
|
from intervention.models import Intervention
|
||||||
from organisation.models import Organisation
|
from organisation.models import Organisation
|
||||||
@ -86,17 +87,12 @@ class KonovaCodeAutocomplete(Select2QuerySetView):
|
|||||||
* c: Search inside a special codelist
|
* 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):
|
def get_queryset(self):
|
||||||
if self.request.user.is_anonymous:
|
if self.request.user.is_anonymous:
|
||||||
return KonovaCode.objects.none()
|
return KonovaCode.objects.none()
|
||||||
qs = KonovaCode.objects.filter(
|
qs = KonovaCode.objects.filter(
|
||||||
is_active=True,
|
is_active=True,
|
||||||
is_leaf=True,
|
parent__isnull=False,
|
||||||
)
|
)
|
||||||
if self.c:
|
if self.c:
|
||||||
qs = qs.filter(
|
qs = qs.filter(
|
||||||
@ -109,4 +105,22 @@ class KonovaCodeAutocomplete(Select2QuerySetView):
|
|||||||
qs.order_by(
|
qs.order_by(
|
||||||
"long_name"
|
"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)
|
||||||
|
@ -18,7 +18,7 @@ from django.contrib import admin
|
|||||||
from django.urls import path, include
|
from django.urls import path, include
|
||||||
|
|
||||||
from konova.autocompletes import OrganisationAutocomplete, NonOfficialOrganisationAutocomplete, EcoAccountAutocomplete, \
|
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.settings import SSO_SERVER, SSO_PUBLIC_KEY, SSO_PRIVATE_KEY, DEBUG
|
||||||
from konova.sso.sso import KonovaSSOClient
|
from konova.sso.sso import KonovaSSOClient
|
||||||
from konova.views import logout_view, home_view, get_document_view, remove_document_view, remove_deadline_view
|
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/orgs/other", NonOfficialOrganisationAutocomplete.as_view(), name="other-orgs-autocomplete"),
|
||||||
path("atcmplt/eco-accounts", EcoAccountAutocomplete.as_view(), name="accounts-autocomplete"),
|
path("atcmplt/eco-accounts", EcoAccountAutocomplete.as_view(), name="accounts-autocomplete"),
|
||||||
path("atcmplt/interventions", InterventionAutocomplete.as_view(), name="interventions-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:
|
if DEBUG:
|
||||||
|
Loading…
Reference in New Issue
Block a user