WIP: CompensationAction using jstree

This commit is contained in:
2022-02-11 14:13:42 +01:00
parent 925d5f5070
commit 23790bca8d
10 changed files with 126 additions and 8 deletions

View File

@@ -11,12 +11,14 @@ 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 konova.contexts import BaseContext
from konova.forms import BaseModalForm, NewDocumentModalForm, RemoveModalForm
from konova.models import DeadlineType
@@ -411,15 +413,11 @@ class NewActionModalForm(BaseModalForm):
required=True,
help_text=_("Select the action type"),
queryset=KonovaCode.objects.filter(
is_archived=False,
is_leaf=True,
code_lists__in=[CODELIST_COMPENSATION_ACTION_ID],
is_archived=False,
),
widget=autocomplete.ModelSelect2Multiple(
url="codes-compensation-action-autocomplete",
attrs={
"data-placeholder": _("Action"),
}
widget=TreeSelectMultiple(
url=None,
),
)
action_type_details = forms.ModelMultipleChoiceField(
@@ -482,6 +480,14 @@ 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
def save(self):
action = self.instance.add_action(self)

View File

@@ -2,6 +2,11 @@
{% 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.
This does not work properly with modal forms, as the scripts are not loaded properly inside the modal.

View File

@@ -2,6 +2,11 @@
{% 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.
This does not work properly with modal forms, as the scripts are not loaded properly inside the modal.