Compensation action code list
* integrates action code list to NewActionForm
This commit is contained in:
		
							parent
							
								
									49f7f3db53
								
							
						
					
					
						commit
						de925c8cc6
					
				@ -41,7 +41,7 @@ class KonovaCode(models.Model):
 | 
			
		||||
 | 
			
		||||
    def __str__(self):
 | 
			
		||||
        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
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -6,6 +6,7 @@ Created on: 04.12.20
 | 
			
		||||
 | 
			
		||||
"""
 | 
			
		||||
from bootstrap_modal_forms.utils import is_ajax
 | 
			
		||||
from dal import autocomplete
 | 
			
		||||
from django import forms
 | 
			
		||||
from django.contrib import messages
 | 
			
		||||
from django.db import transaction
 | 
			
		||||
@ -13,6 +14,7 @@ from django.http import HttpRequest, HttpResponseRedirect
 | 
			
		||||
from django.shortcuts import render
 | 
			
		||||
from django.utils.translation import gettext_lazy as _
 | 
			
		||||
 | 
			
		||||
from codelist.models import KonovaCode
 | 
			
		||||
from compensation.models import Payment, CompensationState, CompensationAction, UnitChoices
 | 
			
		||||
from konova.contexts import BaseContext
 | 
			
		||||
from konova.forms import BaseForm, BaseModalForm
 | 
			
		||||
@ -256,11 +258,21 @@ class NewDeadlineModalForm(BaseModalForm):
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class NewActionModalForm(BaseModalForm):
 | 
			
		||||
    action_type = forms.CharField(
 | 
			
		||||
    action_type = forms.ModelChoiceField(
 | 
			
		||||
        label=_("Action Type"),
 | 
			
		||||
        label_suffix="",
 | 
			
		||||
        required=True,
 | 
			
		||||
        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(
 | 
			
		||||
        label=_("Unit"),
 | 
			
		||||
 | 
			
		||||
@ -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(
 | 
			
		||||
@ -110,3 +106,21 @@ class KonovaCodeAutocomplete(Select2QuerySetView):
 | 
			
		||||
                "long_name"
 | 
			
		||||
            )
 | 
			
		||||
        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 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:
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user