Updated view query sort arguments
authorThierry Florac <tflorac@ulthar.net>
Wed, 19 Sep 2018 10:31:06 +0200
changeset 84 a4c07965e256
parent 83 090b77e9f7c4
child 85 1a37243abeae
Updated view query sort arguments
src/pyams_content_es/shared/view/__init__.py
--- a/src/pyams_content_es/shared/view/__init__.py	Tue Sep 18 16:29:50 2018 +0200
+++ b/src/pyams_content_es/shared/view/__init__.py	Wed Sep 19 10:31:06 2018 +0200
@@ -12,24 +12,20 @@
 
 __docformat__ = 'restructuredtext'
 
-
-# import standard library
 from datetime import datetime
 
-# import interfaces
+from elasticsearch_dsl import Search, Q
+from pyramid.threadlocal import get_current_registry
+from pyramid_es import get_client
+
+from pyams_catalog.query import CatalogResultSet
 from pyams_content.shared.view.interfaces import IWfView, IViewQuery, IViewQueryEsParamsExtension, \
     IViewQueryFilterExtension
-from pyams_workflow.interfaces import IWorkflow
-
-# import packages
-from elasticsearch_dsl import Search, Q
-from pyams_catalog.query import CatalogResultSet
 from pyams_utils.adapter import adapter_config, ContextAdapter
 from pyams_utils.list import unique_iter
 from pyams_utils.request import check_request
 from pyams_utils.timezone import tztime
-from pyramid.threadlocal import get_current_registry
-from pyramid_es import get_client
+from pyams_workflow.interfaces import IWorkflow
 
 
 @adapter_config(name='es', context=IWfView, provides=IViewQuery)
@@ -72,8 +68,12 @@
         params = self.get_es_params(context)
         search = Search(using=client.es, index=client.index) \
             .query(params) \
-            .sort('{0}workflow.{1}'.format('-' if reverse else '',
-                                           sort_index)) \
+            .sort({
+                'workflow.{0}'.format(sort_index): {
+                    'order': 'desc' if reverse else 'asc',
+                    'unmapped_type': 'date'
+                }
+            }) \
             .source(['internal_id'])
         if limit:
             search = search[:limit]