From a008607d408aad2bd016692e04ef4a2be6393b76 Mon Sep 17 00:00:00 2001 From: Roberto Rosario Date: Mon, 10 Jun 2019 02:59:33 -0400 Subject: [PATCH] Support search model list mode Signed-off-by: Roberto Rosario --- mayan/apps/common/literals.py | 3 +++ mayan/apps/documents/apps.py | 5 +++++ mayan/apps/documents/search.py | 9 +++++---- mayan/apps/dynamic_search/classes.py | 8 +++++++- mayan/apps/dynamic_search/views.py | 7 +++++-- mayan/apps/user_management/search.py | 2 +- 6 files changed, 26 insertions(+), 8 deletions(-) diff --git a/mayan/apps/common/literals.py b/mayan/apps/common/literals.py index acebfa08d2..5ca8996a5d 100644 --- a/mayan/apps/common/literals.py +++ b/mayan/apps/common/literals.py @@ -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.' ) diff --git a/mayan/apps/documents/apps.py b/mayan/apps/documents/apps.py index 151523e100..5e8639c466 100644 --- a/mayan/apps/documents/apps.py +++ b/mayan/apps/documents/apps.py @@ -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'] diff --git a/mayan/apps/documents/search.py b/mayan/apps/documents/search.py index b0fbb0d25c..e8a5b7854d 100644 --- a/mayan/apps/documents/search.py +++ b/mayan/apps/documents/search.py @@ -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' ) diff --git a/mayan/apps/dynamic_search/classes.py b/mayan/apps/dynamic_search/classes.py index ce475560f3..3cf7a8523a 100644 --- a/mayan/apps/dynamic_search/classes.py +++ b/mayan/apps/dynamic_search/classes.py @@ -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 diff --git a/mayan/apps/dynamic_search/views.py b/mayan/apps/dynamic_search/views.py index 9bbc79c741..56fa79526d 100644 --- a/mayan/apps/dynamic_search/views.py +++ b/mayan/apps/dynamic_search/views.py @@ -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): diff --git a/mayan/apps/user_management/search.py b/mayan/apps/user_management/search.py index 6fc92d6fd3..0e03323ec1 100644 --- a/mayan/apps/user_management/search.py +++ b/mayan/apps/user_management/search.py @@ -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(