Disable sorting in advanced search if search adapter is using it's own sort algorithm
authorThierry Florac <tflorac@ulthar.net>
Mon, 20 Jul 2020 12:30:49 +0200 (2020-07-20)
changeset 1408 916c81459d6b
parent 1407 85e615286c7a
child 1409 c5d0919c9159
Disable sorting in advanced search if search adapter is using it's own sort algorithm
src/pyams_content/root/zmi/search.py
src/pyams_content/shared/common/zmi/search.py
--- a/src/pyams_content/root/zmi/search.py	Sun Jul 19 02:10:25 2020 +0200
+++ b/src/pyams_content/root/zmi/search.py	Mon Jul 20 12:30:49 2020 +0200
@@ -195,13 +195,17 @@
 
     legend = _("Advanced search")
 
+    fields_interface = ISiteRootAdvancedSearchFields
+    sort_results = True
+
+    prefix = 'search_form.'
+    ajax_handler = 'advanced-search-results.html'
+
     def __init__(self, context, request):
         super(SiteRootAdvancedSearchForm, self).__init__(context, request)
         request.registry.notify(PageletCreatedEvent(self))
         apply_skin(self.request, 'PyAMS admin skin')
 
-    fields_interface = ISiteRootAdvancedSearchFields
-
     @property
     def fields(self):
         fields = field.Fields(self.fields_interface)
@@ -209,8 +213,6 @@
         fields['collections'].widgetFactory = ThesaurusTermsTreeFieldWidget
         return fields
 
-    ajax_handler = 'advanced-search-results.html'
-
     def updateWidgets(self, prefix=None):
         super(SiteRootAdvancedSearchForm, self).updateWidgets(prefix)
         if 'tags' in self.widgets:
@@ -328,11 +330,14 @@
     def data_attributes(self):
         attributes = super(SiteRootAdvancedSearchResultsView, self).data_attributes
         attributes['table'] = {
-            'data-ams-datatable-sorting':
-                "{0},{1}".format(len(self.columns) - 1, self.dt_sort_order),
             'data-ams-datatable-display-length':
                 IAdminProfile(self.request.principal).table_page_length
         }
+        if self.search_form.sort_results:
+            attributes['table']['data-ams-datatable-sorting'] = \
+                "{0},{1}".format(len(self.columns) - 1, self.dt_sort_order)
+        else:
+            attributes['table']['data-ams-datatable-sorting'] = '[]'
         return attributes
 
 
--- a/src/pyams_content/shared/common/zmi/search.py	Sun Jul 19 02:10:25 2020 +0200
+++ b/src/pyams_content/shared/common/zmi/search.py	Mon Jul 20 12:30:49 2020 +0200
@@ -215,6 +215,10 @@
 
     legend = _("Advanced search")
 
+    fields_interface = ISharedToolAdvancedSearchFields
+    sort_results = True
+
+    prefix = 'search_form.'
     ajax_handler = 'advanced-search-results.html'
 
     def __init__(self, context, request):
@@ -222,8 +226,6 @@
         request.registry.notify(PageletCreatedEvent(self))
         apply_skin(self.request, 'PyAMS admin skin')
 
-    fields_interface = ISharedToolAdvancedSearchFields
-
     @property
     def fields(self):
         workflow = IWorkflow(self.context)
@@ -371,11 +373,14 @@
     def data_attributes(self):
         attributes = super(SharedToolAdvancedSearchResultsView, self).data_attributes
         attributes['table'] = {
-            'data-ams-datatable-sorting':
-                "{0},{1}".format(len(self.columns) - 1, self.dt_sort_order),
             'data-ams-datatable-display-length':
                 IAdminProfile(self.request.principal).table_page_length
         }
+        if self.search_form.sort_results:
+            attributes['table']['data-ams-datatable-sorting'] = \
+                "{0},{1}".format(len(self.columns) - 1, self.dt_sort_order)
+        else:
+            attributes['table']['data-ams-datatable-sorting'] = '[]'
         return attributes