#112 Autocomplete enhancements
* enhances filtering for Autocomplete -> parent_parent will be searched for match as well * adds rendering of parent_parent group for BiotopeAutocomplete * enhances ordering of registration office autocomplete
This commit is contained in:
parent
1ea5b4fc39
commit
a160f3fe6c
@ -5,7 +5,12 @@ Contact: michel.peltriaux@sgdnord.rlp.de
|
||||
Created on: 07.12.20
|
||||
|
||||
"""
|
||||
import collections
|
||||
|
||||
from dal_select2.views import Select2QuerySetView, Select2GroupQuerySetView
|
||||
from django.core.exceptions import ImproperlyConfigured
|
||||
|
||||
from konova.utils.message_templates import UNGROUPED
|
||||
from user.models import User
|
||||
from django.db.models import Q
|
||||
|
||||
@ -139,6 +144,8 @@ class KonovaCodeAutocomplete(Select2GroupQuerySetView):
|
||||
q_or |= Q(short_name__icontains=keyword)
|
||||
q_or |= Q(parent__long_name__icontains=keyword)
|
||||
q_or |= Q(parent__short_name__icontains=keyword)
|
||||
q_or |= Q(parent__parent__long_name__icontains=keyword)
|
||||
q_or |= Q(parent__parent__short_name__icontains=keyword)
|
||||
_filter.add(q_or, Q.AND)
|
||||
qs = qs.filter(_filter).distinct()
|
||||
return qs
|
||||
@ -214,6 +221,41 @@ class BiotopeCodeAutocomplete(KonovaCodeAutocomplete):
|
||||
def get_result_label(self, result):
|
||||
return f"{result.long_name} ({result.short_name})"
|
||||
|
||||
def get_results(self, context):
|
||||
"""Return the options grouped by a common related model.
|
||||
|
||||
Raises ImproperlyConfigured if self.group_by_name is not configured
|
||||
"""
|
||||
if not self.group_by_related:
|
||||
raise ImproperlyConfigured("Missing group_by_related.")
|
||||
|
||||
super_groups = collections.OrderedDict()
|
||||
|
||||
object_list = context['object_list']
|
||||
|
||||
for result in object_list:
|
||||
group = result.parent if result.parent else None
|
||||
group_name = f"{group.long_name} ({group.short_name})" if group else UNGROUPED
|
||||
super_group = result.parent.parent if result.parent else None
|
||||
super_group_name = f"{super_group.long_name} ({super_group.short_name})" if super_group else UNGROUPED
|
||||
super_groups.setdefault(super_group_name, {})
|
||||
super_groups[super_group_name].setdefault(group_name, [])
|
||||
super_groups[super_group_name][group_name].append(result)
|
||||
|
||||
return [{
|
||||
'id': None,
|
||||
'text': super_group,
|
||||
'children': [{
|
||||
"id": None,
|
||||
"text": group,
|
||||
"children": [{
|
||||
'id': self.get_result_value(result),
|
||||
'text': self.get_result_label(result),
|
||||
'selected_text': self.get_selected_result_label(result),
|
||||
} for result in results]
|
||||
} for group, results in groups.items()]
|
||||
} for super_group, groups in super_groups.items()]
|
||||
|
||||
|
||||
class BiotopeExtraCodeAutocomplete(KonovaCodeAutocomplete):
|
||||
"""
|
||||
@ -284,6 +326,11 @@ class RegistrationOfficeCodeAutocomplete(KonovaCodeAutocomplete):
|
||||
self.c = CODELIST_REGISTRATION_OFFICE_ID
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
def order_by(self, qs):
|
||||
return qs.order_by(
|
||||
"parent__long_name"
|
||||
)
|
||||
|
||||
|
||||
class ConservationOfficeCodeAutocomplete(KonovaCodeAutocomplete):
|
||||
"""
|
||||
@ -297,4 +344,4 @@ class ConservationOfficeCodeAutocomplete(KonovaCodeAutocomplete):
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
def get_result_label(self, result):
|
||||
return f"{result.long_name} ({result.short_name})"
|
||||
return f"{result.long_name} ({result.short_name})"
|
||||
|
@ -242,15 +242,24 @@ Similar to bootstraps 'shadow-lg'
|
||||
.select2-results__option--highlighted{
|
||||
background-color: var(--rlp-red) !important;
|
||||
}
|
||||
/*
|
||||
.select2-container--default .select2-results__group{
|
||||
background-color: var(--rlp-gray-light);
|
||||
}
|
||||
.select2-container--default .select2-results__option .select2-results__option{
|
||||
padding-left: 2em !important;
|
||||
padding-left: 1em !important;
|
||||
}
|
||||
|
||||
*/
|
||||
.select2-results__options--nested{
|
||||
padding-left: 1em !important;
|
||||
}
|
||||
.select2-container--default .select2-results > .select2-results__options{
|
||||
max-height: 500px !important;
|
||||
}
|
||||
/*
|
||||
.select2-container--default .select2-results__option .select2-results__option{
|
||||
padding-left: 2em;
|
||||
}
|
||||
}
|
||||
|
||||
*/
|
@ -7,7 +7,7 @@ Created on: 02.08.21
|
||||
"""
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
|
||||
UNGROUPED = _("Ungrouped")
|
||||
FORM_INVALID = _("There was an error on this form.")
|
||||
PARAMS_INVALID = _("Invalid parameters")
|
||||
INTERVENTION_INVALID = _("There are errors in this intervention.")
|
||||
|
Binary file not shown.
@ -26,7 +26,7 @@ msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: PACKAGE VERSION\n"
|
||||
"Report-Msgid-Bugs-To: \n"
|
||||
"POT-Creation-Date: 2022-02-15 11:27+0100\n"
|
||||
"POT-Creation-Date: 2022-02-15 15:29+0100\n"
|
||||
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
||||
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
||||
"Language-Team: LANGUAGE <LL@li.org>\n"
|
||||
@ -565,8 +565,9 @@ msgid ""
|
||||
"action types are expected to be performed according to the amount and unit "
|
||||
"below on this form."
|
||||
msgstr ""
|
||||
"Eine Maßnahme kann aus mehreren verschiedenen Maßnahmentypen bestehen. Alle hier gewählten "
|
||||
"Einträge sollen mit der weiter unten angegebenen Einheit und Menge umgesetzt werden. "
|
||||
"Eine Maßnahme kann aus mehreren verschiedenen Maßnahmentypen bestehen. Alle "
|
||||
"hier gewählten Einträge sollen mit der weiter unten angegebenen Einheit und "
|
||||
"Menge umgesetzt werden. "
|
||||
|
||||
#: compensation/forms/modalForms.py:418 compensation/forms/modalForms.py:430
|
||||
msgid "Action Type detail"
|
||||
@ -1765,6 +1766,11 @@ msgstr "Neu"
|
||||
msgid "Show"
|
||||
msgstr "Anzeigen"
|
||||
|
||||
#: konova/templates/konova/widgets/checkbox-tree-select.html:4
|
||||
#: templates/generic_index.html:56
|
||||
msgid "Search"
|
||||
msgstr "Suchen"
|
||||
|
||||
#: konova/templates/konova/widgets/generate-content-input.html:6
|
||||
msgid "Generate new"
|
||||
msgstr "Neu generieren"
|
||||
@ -1805,6 +1811,10 @@ msgstr "{} - Freigegebene Daten geprüft"
|
||||
msgid "Request for new API token"
|
||||
msgstr "Anfrage für neuen API Token"
|
||||
|
||||
#: konova/utils/message_templates.py:10
|
||||
msgid "Ungrouped"
|
||||
msgstr "Ohne Zuordnung"
|
||||
|
||||
#: konova/utils/message_templates.py:11
|
||||
msgid "There was an error on this form."
|
||||
msgstr "Es gab einen Fehler im Formular."
|
||||
@ -2270,10 +2280,6 @@ msgstr "Neu"
|
||||
msgid "Search for keywords"
|
||||
msgstr "Nach Schlagwörtern suchen"
|
||||
|
||||
#: templates/generic_index.html:56
|
||||
msgid "Search"
|
||||
msgstr "Suchen"
|
||||
|
||||
#: templates/generic_index.html:57
|
||||
msgid "Start search"
|
||||
msgstr "Starte Suche"
|
||||
|
Loading…
Reference in New Issue
Block a user