#112 CompensationAction Tree
* implements generic HTML based and Django compatible TreeView * enhances listing of CompensationActions on DetailView
This commit is contained in:
@@ -11,14 +11,13 @@ from django import forms
|
||||
from django.contrib import messages
|
||||
from django.http import HttpRequest, HttpResponseRedirect
|
||||
from django.shortcuts import render
|
||||
from django.urls import reverse
|
||||
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, CODELIST_BIOTOPES_EXTRA_CODES_ID, \
|
||||
CODELIST_COMPENSATION_ACTION_DETAIL_ID
|
||||
from compensation.models import CompensationDocument, EcoAccountDocument
|
||||
from intervention.inputs import TreeSelectMultiple
|
||||
from intervention.inputs import CompensationActionTreeCheckboxSelectMultiple
|
||||
from konova.contexts import BaseContext
|
||||
from konova.forms import BaseModalForm, NewDocumentModalForm, RemoveModalForm
|
||||
from konova.models import DeadlineType
|
||||
@@ -407,18 +406,13 @@ class NewActionModalForm(BaseModalForm):
|
||||
|
||||
"""
|
||||
from compensation.models import UnitChoices
|
||||
action_type = forms.ModelMultipleChoiceField(
|
||||
action_type = forms.MultipleChoiceField(
|
||||
label=_("Action Type"),
|
||||
label_suffix="",
|
||||
required=True,
|
||||
help_text=_("Select the action type"),
|
||||
queryset=KonovaCode.objects.filter(
|
||||
code_lists__in=[CODELIST_COMPENSATION_ACTION_ID],
|
||||
is_archived=False,
|
||||
),
|
||||
widget=TreeSelectMultiple(
|
||||
url=None,
|
||||
),
|
||||
choices=[],
|
||||
widget=CompensationActionTreeCheckboxSelectMultiple(),
|
||||
)
|
||||
action_type_details = forms.ModelMultipleChoiceField(
|
||||
label=_("Action Type detail"),
|
||||
@@ -480,14 +474,16 @@ class NewActionModalForm(BaseModalForm):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.form_title = _("New action")
|
||||
self.form_caption = _("Insert data for the new action")
|
||||
url = reverse("codes-action-children")
|
||||
self.fields["action_type"].widget.attrs = {
|
||||
"url": url,
|
||||
}
|
||||
|
||||
def is_valid(self):
|
||||
super_valid = super().is_valid()
|
||||
return super_valid
|
||||
choices =KonovaCode.objects.filter(
|
||||
code_lists__in=[CODELIST_COMPENSATION_ACTION_ID],
|
||||
is_archived=False,
|
||||
is_leaf=True,
|
||||
).values_list("id", flat=True)
|
||||
choices = [
|
||||
(choice, choice)
|
||||
for choice in choices
|
||||
]
|
||||
self.fields["action_type"].choices = choices
|
||||
|
||||
def save(self):
|
||||
action = self.instance.add_action(self)
|
||||
@@ -502,7 +498,7 @@ class EditCompensationActionModalForm(NewActionModalForm):
|
||||
self.action = kwargs.pop("action", None)
|
||||
super().__init__(*args, **kwargs)
|
||||
form_data = {
|
||||
"action_type": self.action.action_type.all(),
|
||||
"action_type": list(self.action.action_type.values_list("id", flat=True)),
|
||||
"action_type_details": self.action.action_type_details.all(),
|
||||
"amount": self.action.amount,
|
||||
"unit": self.action.unit,
|
||||
|
||||
Reference in New Issue
Block a user