#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,
|
||||
|
||||
@@ -47,17 +47,15 @@
|
||||
{% for action in actions %}
|
||||
<tr>
|
||||
<td class="">
|
||||
<ul>
|
||||
{% for type in action.action_type.all %}
|
||||
<li> {{type}} </li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% if action.action_type_details.count > 0 %}
|
||||
<br>
|
||||
{% for detail in action.action_type_details.all %}
|
||||
<span class="badge badge-pill rlp-r" title="{{detail}}">{{detail.long_name}}</span>
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
{% for type in action.action_type.all %}
|
||||
<div> {{type.parent.parent.long_name}} {% fa5_icon 'angle-right' %} {{type.parent.long_name}} {% fa5_icon 'angle-right' %} {{type.long_name}} </div>
|
||||
<hr>
|
||||
{% endfor %}
|
||||
{% for detail in action.action_type_details.all %}
|
||||
<span class="badge badge-pill rlp-r" title="{{detail}}">{{detail.long_name}}</span>
|
||||
{% empty %}
|
||||
<span class="badge badge-pill rlp-r-outline" title="{% trans 'No action type details' %}">{% trans 'No action type details' %}</span>
|
||||
{% endfor %}
|
||||
</td>
|
||||
<td class="">{{ action.amount|floatformat:2|intcomma }} {{ action.unit_humanize }}</td>
|
||||
<td class="">
|
||||
|
||||
@@ -2,10 +2,6 @@
|
||||
{% load i18n l10n static fontawesome_5 humanize ksp_filters %}
|
||||
|
||||
{% block head %}
|
||||
{% comment %}
|
||||
Needed for custom Checkbox Tree Select Widget
|
||||
{% endcomment %}
|
||||
{% include 'form/scripts/jstree-scripts.html' %}
|
||||
|
||||
{% comment %}
|
||||
dal documentation (django-autocomplete-light) states using form.media for adding needed scripts.
|
||||
|
||||
@@ -46,17 +46,15 @@
|
||||
{% for action in actions %}
|
||||
<tr>
|
||||
<td class="">
|
||||
<ul>
|
||||
{% for type in action.action_type.all%}
|
||||
<li> {{type.long_name}} </li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% if action.action_type_details.count > 0 %}
|
||||
<br>
|
||||
{% for detail in action.action_type_details.all %}
|
||||
<span class="badge badge-pill rlp-r" title="{{detail}}">{{detail.long_name}}</span>
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
{% for type in action.action_type.all %}
|
||||
<div> {{type.parent.parent.long_name}} {% fa5_icon 'angle-right' %} {{type.parent.long_name}} {% fa5_icon 'angle-right' %} {{type.long_name}} </div>
|
||||
<hr>
|
||||
{% endfor %}
|
||||
{% for detail in action.action_type_details.all %}
|
||||
<span class="badge badge-pill rlp-r" title="{{detail}}">{{detail.long_name}}</span>
|
||||
{% empty %}
|
||||
<span class="badge badge-pill rlp-r-outline" title="{% trans 'No action type details' %}">{% trans 'No action type details' %}</span>
|
||||
{% endfor %}
|
||||
</td>
|
||||
<td class="">{{ action.amount|floatformat:2|intcomma }} {{ action.unit_humanize }}</td>
|
||||
<td class="">
|
||||
|
||||
@@ -2,10 +2,6 @@
|
||||
{% load i18n l10n static fontawesome_5 humanize %}
|
||||
|
||||
{% block head %}
|
||||
{% comment %}
|
||||
Needed for custom Checkbox Tree Select Widget
|
||||
{% endcomment %}
|
||||
{% include 'form/scripts/jstree-scripts.html' %}
|
||||
|
||||
{% comment %}
|
||||
dal documentation (django-autocomplete-light) states using form.media for adding needed scripts.
|
||||
|
||||
Reference in New Issue
Block a user