#112 CompensationAction Tree
* implements generic HTML based and Django compatible TreeView * enhances listing of CompensationActions on DetailView
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
from django import forms
|
||||
from django.urls import reverse
|
||||
from codelist.models import KonovaCode
|
||||
from codelist.settings import CODELIST_COMPENSATION_ACTION_ID
|
||||
|
||||
|
||||
class DummyFilterInput(forms.HiddenInput):
|
||||
@@ -33,15 +34,49 @@ class GenerateInput(forms.TextInput):
|
||||
template_name = "konova/widgets/generate-content-input.html"
|
||||
|
||||
|
||||
class TreeSelectMultiple(forms.SelectMultiple):
|
||||
class TreeCheckboxSelectMultiple(forms.CheckboxSelectMultiple):
|
||||
""" Provides multiple selection of parent-child data
|
||||
|
||||
"""
|
||||
template_name = "konova/widgets/checkbox-tree-select-base.html"
|
||||
url = None
|
||||
template_name = "konova/widgets/checkbox-tree-select.html"
|
||||
|
||||
class meta:
|
||||
abstract = True
|
||||
|
||||
|
||||
class KonovaCodeTreeCheckboxSelectMultiple(TreeCheckboxSelectMultiple):
|
||||
""" Provides multiple selection of KonovaCodes
|
||||
|
||||
"""
|
||||
filter = None
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
self.url = kwargs.pop("url", None)
|
||||
if self.url:
|
||||
self.url = reverse(self.url)
|
||||
self.code_list = kwargs.pop("code_list", None)
|
||||
self.filter = kwargs.pop("filter", {})
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
def get_context(self, name, value, attrs):
|
||||
context = super().get_context(name, value, attrs)
|
||||
codes = KonovaCode.objects.filter(
|
||||
**self.filter,
|
||||
)
|
||||
codes = [
|
||||
parent_code.add_children()
|
||||
for parent_code in codes
|
||||
]
|
||||
context["codes"] = codes
|
||||
return context
|
||||
|
||||
|
||||
class CompensationActionTreeCheckboxSelectMultiple(KonovaCodeTreeCheckboxSelectMultiple):
|
||||
""" Provides multiple selection of CompensationActions
|
||||
|
||||
"""
|
||||
filter = None
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.filter = {
|
||||
"code_lists__in": [CODELIST_COMPENSATION_ACTION_ID],
|
||||
"parent": None,
|
||||
}
|
||||
Reference in New Issue
Block a user