Support search model list mode
Signed-off-by: Roberto Rosario <roberto.rosario.gonzalez@gmail.com>
This commit is contained in:
@@ -8,6 +8,8 @@ from django.utils.encoding import force_text, python_2_unicode_compatible
|
||||
from django.utils.module_loading import import_string
|
||||
from django.utils.translation import ugettext as _
|
||||
|
||||
from mayan.apps.common.literals import LIST_MODE_CHOICE_LIST
|
||||
|
||||
from .literals import (
|
||||
QUERY_OPERATION_AND, QUERY_OPERATION_OR, TERM_NEGATION_CHARACTER,
|
||||
TERM_OPERATION_OR, TERM_OPERATIONS, TERM_QUOTES, TERM_SPACE_CHARACTER
|
||||
@@ -101,8 +103,12 @@ class SearchModel(object):
|
||||
|
||||
return result
|
||||
|
||||
def __init__(self, app_label, model_name, serializer_path, label=None, permission=None):
|
||||
def __init__(
|
||||
self, app_label, model_name, serializer_path, label=None,
|
||||
list_mode=None, permission=None
|
||||
):
|
||||
self.app_label = app_label
|
||||
self.list_mode = list_mode or LIST_MODE_CHOICE_LIST
|
||||
self.model_name = model_name
|
||||
self.search_fields = []
|
||||
self._model = None # Lazy
|
||||
|
||||
@@ -7,6 +7,7 @@ from django.utils.translation import ugettext_lazy as _
|
||||
from django.views.generic.base import RedirectView
|
||||
|
||||
from mayan.apps.common.generics import SimpleView, SingleObjectListView
|
||||
from mayan.apps.common.literals import LIST_MODE_CHOICE_ITEM
|
||||
|
||||
from .forms import SearchForm, AdvancedSearchForm
|
||||
from .icons import icon_search_submit
|
||||
@@ -18,8 +19,7 @@ logger = logging.getLogger(__name__)
|
||||
class ResultsView(SearchModelMixin, SingleObjectListView):
|
||||
def get_extra_context(self):
|
||||
context = {
|
||||
'hide_links': True,
|
||||
'list_as_items': True,
|
||||
'hide_object': True,
|
||||
'no_results_icon': icon_search_submit,
|
||||
'no_results_text': _(
|
||||
'Try again using different terms. '
|
||||
@@ -29,6 +29,9 @@ class ResultsView(SearchModelMixin, SingleObjectListView):
|
||||
'title': _('Search results for: %s') % self.search_model.label,
|
||||
}
|
||||
|
||||
if self.search_model.list_mode == LIST_MODE_CHOICE_ITEM:
|
||||
context['list_as_items'] = True
|
||||
|
||||
return context
|
||||
|
||||
def get_source_queryset(self):
|
||||
|
||||
Reference in New Issue
Block a user