WIP: JS Tree improvements
* adds optional short_name rendering for selectable codes * refactors autocomplete field for compensation state into custom js tree widget * adds single select (radio) alternative to tree widget templates
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
from django import forms
|
||||
from codelist.models import KonovaCode
|
||||
from codelist.settings import CODELIST_COMPENSATION_ACTION_ID
|
||||
from codelist.settings import CODELIST_COMPENSATION_ACTION_ID, CODELIST_BIOTOPES_ID
|
||||
|
||||
|
||||
class DummyFilterInput(forms.HiddenInput):
|
||||
@@ -38,7 +38,17 @@ class TreeCheckboxSelectMultiple(forms.CheckboxSelectMultiple):
|
||||
""" Provides multiple selection of parent-child data
|
||||
|
||||
"""
|
||||
template_name = "konova/widgets/checkbox-tree-select.html"
|
||||
template_name = "konova/widgets/tree/checkbox/checkbox-tree-select.html"
|
||||
|
||||
class meta:
|
||||
abstract = True
|
||||
|
||||
|
||||
class TreeRadioSelect(forms.RadioSelect):
|
||||
""" Provides single selection of parent-child data
|
||||
|
||||
"""
|
||||
template_name = "konova/widgets/tree/radio/radio-tree-select.html"
|
||||
|
||||
class meta:
|
||||
abstract = True
|
||||
@@ -68,6 +78,30 @@ class KonovaCodeTreeCheckboxSelectMultiple(TreeCheckboxSelectMultiple):
|
||||
return context
|
||||
|
||||
|
||||
class KonovaCodeTreeRadioSelect(TreeRadioSelect):
|
||||
""" Provides single selection of KonovaCode
|
||||
|
||||
"""
|
||||
filter = None
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
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
|
||||
|
||||
@@ -79,4 +113,31 @@ class CompensationActionTreeCheckboxSelectMultiple(KonovaCodeTreeCheckboxSelectM
|
||||
self.filter = {
|
||||
"code_lists__in": [CODELIST_COMPENSATION_ACTION_ID],
|
||||
"parent": None,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class CompensationStateTreeRadioSelect(KonovaCodeTreeRadioSelect):
|
||||
""" Provides single selection of CompensationState
|
||||
|
||||
"""
|
||||
filter = None
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.filter = {
|
||||
"code_lists__in": [CODELIST_BIOTOPES_ID],
|
||||
"parent": None,
|
||||
"is_archived": False,
|
||||
}
|
||||
|
||||
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("short_name")
|
||||
for parent_code in codes
|
||||
]
|
||||
context["codes"] = codes
|
||||
return context
|
||||
Reference in New Issue
Block a user