Konova code improvements
* improves rendering of codes as string (short names will be used if existing) * reduces selectable konova codes to leafs (as discussed with experts) * automatically resizes the width of modal form fields to w-100 * adds/updates translations
This commit is contained in:
@@ -6,6 +6,7 @@ Created on: 07.12.20
|
||||
|
||||
"""
|
||||
from dal_select2.views import Select2QuerySetView
|
||||
from django.db.models import Q
|
||||
|
||||
from codelist.models import KonovaCode
|
||||
from codelist.settings import CODELIST_COMPENSATION_ACTION_ID, CODELIST_BIOTOPES_ID
|
||||
@@ -92,19 +93,19 @@ class KonovaCodeAutocomplete(Select2QuerySetView):
|
||||
return KonovaCode.objects.none()
|
||||
qs = KonovaCode.objects.filter(
|
||||
is_active=True,
|
||||
parent__isnull=False,
|
||||
is_leaf=True,
|
||||
).order_by(
|
||||
"long_name"
|
||||
)
|
||||
if self.c:
|
||||
qs = qs.filter(
|
||||
code_lists__in=[self.c]
|
||||
)
|
||||
if self.q:
|
||||
qs = qs.filter(
|
||||
long_name__icontains=self.q
|
||||
)
|
||||
qs.order_by(
|
||||
"long_name"
|
||||
)
|
||||
q_or = Q()
|
||||
q_or |= Q(long_name__icontains=self.q)
|
||||
q_or |= Q(short_name__icontains=self.q)
|
||||
qs = qs.filter(q_or)
|
||||
return qs
|
||||
|
||||
|
||||
|
||||
@@ -155,6 +155,16 @@ class BaseModalForm(BaseForm, BSModalForm):
|
||||
render_submit = True
|
||||
template = "modal/modal_form.html"
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
# Automatically add bootstrap w-100 class for maximum width of form fields in modals
|
||||
for key, val in self.fields.items():
|
||||
val.widget.attrs.update(
|
||||
{
|
||||
"class": "w-100"
|
||||
}
|
||||
)
|
||||
|
||||
def process_request(self, request: HttpRequest, msg_success: str = _("Object removed"), msg_error: str = FORM_INVALID, redirect_url: str = None):
|
||||
""" Generic processing of request
|
||||
|
||||
@@ -249,6 +259,8 @@ class RemoveModalForm(BaseModalForm):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.form_title = _("Remove")
|
||||
self.form_caption = _("Are you sure?")
|
||||
# Disable automatic w-100 setting for this type of modal form. Looks kinda strange
|
||||
self.fields["confirm"].widget.attrs["class"] = ""
|
||||
|
||||
def save(self):
|
||||
if isinstance(self.instance, BaseObject):
|
||||
|
||||
Reference in New Issue
Block a user