Updated view query to filter contents based on workflow publication dates
authorThierry Florac <thierry.florac@onf.fr>
Wed, 12 Jul 2017 12:03:17 +0200
changeset 16 e5add18ddc33
parent 15 70adcc5ac29c
child 17 4d9c23cdfa82
Updated view query to filter contents based on workflow publication dates
src/pyams_content_es/component/view.py
--- a/src/pyams_content_es/component/view.py	Wed Jul 12 12:02:14 2017 +0200
+++ b/src/pyams_content_es/component/view.py	Wed Jul 12 12:03:17 2017 +0200
@@ -14,6 +14,7 @@
 
 
 # import standard library
+from datetime import datetime
 
 # import interfaces
 from pyams_content.shared.view.interfaces import IWfView, IViewQuery, IViewQueryEsParamsExtension, \
@@ -26,6 +27,7 @@
 from pyams_utils.adapter import adapter_config, ContextAdapter
 from pyams_utils.list import unique
 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
 
@@ -42,6 +44,10 @@
         for workflow in registry.getAllUtilitiesRegisteredFor(IWorkflow):
             wf_params.extend(workflow.published_states)
         params &= Q('terms', **{'workflow.status': wf_params})
+        now = tztime(datetime.utcnow())
+        params &= Q('range', **{'workflow.effective_date': {'lte': now}})
+        params &= Q('bool', must=Q('range', **{'workflow.push_end_date': {'gte': now}})) | \
+                  Q('bool', must_not=Q('exists', **{'field': 'workflow.push_end_date'}))
         for name, adapter in sorted(registry.getAdapters((view,), IViewQueryEsParamsExtension),
                                     key=lambda x: x[1].weight):
             new_params = adapter.get_es_params(context)