Support search model list mode
Signed-off-by: Roberto Rosario <roberto.rosario.gonzalez@gmail.com>
This commit is contained in:
@@ -6,6 +6,9 @@ DEFAULT_COMMON_HOME_VIEW = 'common:home'
|
||||
DELETE_STALE_UPLOADS_INTERVAL = 60 * 10 # 10 minutes
|
||||
DJANGO_SQLITE_BACKEND = 'django.db.backends.sqlite3'
|
||||
|
||||
LIST_MODE_CHOICE_LIST = 'list'
|
||||
LIST_MODE_CHOICE_ITEM = 'item'
|
||||
|
||||
MESSAGE_DEPRECATION_WARNING = _(
|
||||
'This feature has been deprecated and will be removed in a future version.'
|
||||
)
|
||||
|
||||
@@ -269,6 +269,11 @@ class DocumentsApp(MayanAppConfig):
|
||||
instance=context['object']
|
||||
), label=_('Thumbnail'), source=DocumentPage
|
||||
)
|
||||
|
||||
SourceColumn(
|
||||
attribute='get_label', is_identifier=True,
|
||||
is_object_absolute_url=True, source=DocumentPageResult
|
||||
)
|
||||
SourceColumn(
|
||||
func=lambda context: document_page_thumbnail_widget.render(
|
||||
instance=context['object']
|
||||
|
||||
@@ -2,6 +2,7 @@ from __future__ import absolute_import, unicode_literals
|
||||
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from mayan.apps.common.literals import LIST_MODE_CHOICE_ITEM
|
||||
from mayan.apps.dynamic_search.classes import SearchModel
|
||||
|
||||
from .permissions import permission_document_view
|
||||
@@ -12,8 +13,8 @@ def format_uuid(term_string):
|
||||
|
||||
|
||||
document_search = SearchModel(
|
||||
app_label='documents', model_name='Document',
|
||||
permission=permission_document_view,
|
||||
app_label='documents', list_mode=LIST_MODE_CHOICE_ITEM,
|
||||
model_name='Document', permission=permission_document_view,
|
||||
serializer_path='mayan.apps.documents.serializers.DocumentSerializer'
|
||||
)
|
||||
|
||||
@@ -33,8 +34,8 @@ document_search.add_model_field(
|
||||
)
|
||||
|
||||
document_page_search = SearchModel(
|
||||
app_label='documents', model_name='DocumentPageResult',
|
||||
permission=permission_document_view,
|
||||
app_label='documents', list_mode=LIST_MODE_CHOICE_ITEM,
|
||||
model_name='DocumentPageResult', permission=permission_document_view,
|
||||
serializer_path='mayan.apps.documents.serializers.DocumentPageSerializer'
|
||||
)
|
||||
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -34,7 +34,7 @@ user_search.add_model_field(
|
||||
group_search = SearchModel(
|
||||
app_label='auth', label=_('Group'), model_name='Group',
|
||||
permission=permission_group_view,
|
||||
serializer_path='user_management.serializers.GroupSerializer'
|
||||
serializer_path='mayan.apps.user_management.serializers.GroupSerializer'
|
||||
)
|
||||
|
||||
group_search.add_model_field(
|
||||
|
||||
Reference in New Issue
Block a user