Compare commits

..

No commits in common. "d04d02380f6ec763ff24fe61babd2aa2e6c9344b" and "2b66189590e32a9faeb113446c4883d4b64333ed" have entirely different histories.

11 changed files with 10 additions and 115 deletions

View File

@ -11,18 +11,16 @@ 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
from konova.utils.message_templates import FORM_INVALID, ADDED_COMPENSATION_STATE, \
from konova.utils.message_templates import FORM_INVALID, ADDED_COMPENSATION_STATE, ADDED_DEADLINE, \
ADDED_COMPENSATION_ACTION, PAYMENT_EDITED, COMPENSATION_STATE_EDITED, COMPENSATION_ACTION_EDITED, DEADLINE_EDITED
@ -413,11 +411,15 @@ class NewActionModalForm(BaseModalForm):
required=True,
help_text=_("Select the action type"),
queryset=KonovaCode.objects.filter(
code_lists__in=[CODELIST_COMPENSATION_ACTION_ID],
is_archived=False,
is_leaf=True,
code_lists__in=[CODELIST_COMPENSATION_ACTION_ID],
),
widget=TreeSelectMultiple(
url=None,
widget=autocomplete.ModelSelect2Multiple(
url="codes-compensation-action-autocomplete",
attrs={
"data-placeholder": _("Action"),
}
),
)
action_type_details = forms.ModelMultipleChoiceField(
@ -480,14 +482,6 @@ 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

@ -9,12 +9,9 @@ def migrate_actions(apps, schema_editor):
for action in actions:
action_type = action.action_type or []
action.action_type_tmp.set([action_type])
action.action_type_tmp.set(action_type)
action.save()
if not action.action_type_tmp.count() > 0:
raise ValueError("Migration of actions did not work! Stoped before data loss!")
class Migration(migrations.Migration):

View File

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

View File

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

View File

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

View File

@ -1,5 +1,4 @@
from django import forms
from django.urls import reverse
class DummyFilterInput(forms.HiddenInput):
@ -31,17 +30,3 @@ class GenerateInput(forms.TextInput):
"""
template_name = "konova/widgets/generate-content-input.html"
class TreeSelectMultiple(forms.SelectMultiple):
""" Provides multiple selection of parent-child data
"""
template_name = "konova/widgets/checkbox-tree-select-base.html"
url = None
def __init__(self, *args, **kwargs):
self.url = kwargs.pop("url", None)
if self.url:
self.url = reverse(self.url)
super().__init__(*args, **kwargs)

View File

@ -1,29 +0,0 @@
<div id="jstree"></div>
<input id="jstree-input" name="{{ widget.name }}" hidden="hidden"/>
<script>
$(function () {
$('#jstree').jstree({
'plugins': [
'checkbox',
'wholerow',
],
'core' : {
'data' : {
'url' : '{{ widget.attrs.url }}',
'data' : function (node) {
return { 'id' : node.id };
}
}
}
});
$('#jstree')
.on('deselect_node.jstree', function (e, data) {
$('#jstree-input').val(data.selected);
})
.on('select_node.jstree', function (e, data) {
$('#jstree-input').val(data.selected);
})
});
</script>

View File

@ -1,9 +0,0 @@
{% load l10n %}
<ul>
{% for code in codes %}
<li id="{{code.pk|unlocalize}}" class="{% if code.is_leaf%}jstree-leaf{% else %}jstree-closed{% endif %}">
{{code.long_name}}
</li>
{% endfor %}
</ul>

View File

@ -23,7 +23,7 @@ from konova.autocompletes import EcoAccountAutocomplete, \
ShareUserAutocomplete, BiotopeExtraCodeAutocomplete, CompensationActionDetailCodeAutocomplete
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_konova_code_action_children
from konova.views import logout_view, home_view
sso_client = KonovaSSOClient(SSO_SERVER, SSO_PUBLIC_KEY, SSO_PRIVATE_KEY)
urlpatterns = [
@ -40,8 +40,6 @@ urlpatterns = [
path('analysis/', include("analysis.urls")),
path('api/', include("api.urls")),
path("codes/comp/action/children", get_konova_code_action_children, name="codes-action-children"),
# Autocomplete paths for all apps
path("atcmplt/eco-accounts", EcoAccountAutocomplete.as_view(), name="accounts-autocomplete"),
path("atcmplt/interventions", InterventionAutocomplete.as_view(), name="interventions-autocomplete"),

View File

@ -9,12 +9,9 @@ from django.contrib.auth import logout
from django.contrib.auth.decorators import login_required
from django.http import HttpRequest, FileResponse
from django.shortcuts import redirect, render, get_object_or_404
from django.template.loader import render_to_string
from django.utils import timezone
from django.utils.translation import gettext_lazy as _
from codelist.models import KonovaCode
from codelist.settings import CODELIST_COMPENSATION_ACTION_ID
from compensation.models import Compensation, EcoAccount
from intervention.models import Intervention
from konova.contexts import BaseContext
@ -127,24 +124,3 @@ def get_500_view(request: HttpRequest):
"""
context = BaseContext.context
return render(request, "500.html", context, status=500)
@login_required
def get_konova_code_action_children(request: HttpRequest):
template = "konova/widgets/checkbox-tree-select-content.html"
_id = request.GET.get("id", None)
if _id == "#":
# Return all!
codes = KonovaCode.objects.filter(
code_lists__in=[CODELIST_COMPENSATION_ACTION_ID],
parent=None,
)
else:
codes = KonovaCode.objects.filter(
code_lists__in=[CODELIST_COMPENSATION_ACTION_ID],
parent__id=_id,
)
context = {
"codes": codes
}
return render(request, template, context)

View File

@ -1,2 +0,0 @@
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jstree/3.2.1/themes/default/style.min.css" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/jstree/3.2.1/jstree.min.js"></script>