Add search on workflow publication attributes to views
authorThierry Florac <thierry.florac@onf.fr>
Wed, 12 Jul 2017 11:57:50 +0200
changeset 115 67a6a3b92612
parent 114 7799437055f1
child 116 f356c84860a3
Add search on workflow publication attributes to views
src/pyams_content/shared/view/__init__.py
--- a/src/pyams_content/shared/view/__init__.py	Wed Jul 12 11:55:25 2017 +0200
+++ b/src/pyams_content/shared/view/__init__.py	Wed Jul 12 11:57:50 2017 +0200
@@ -17,6 +17,8 @@
 import logging
 logger = logging.getLogger("PyAMS (content)")
 
+from datetime import datetime
+
 # import interfaces
 from hypatia.interfaces import ICatalog
 from pyams_content.shared.view.interfaces import IView, IWfView, IViewQuery, IViewQueryParamsExtension, \
@@ -26,13 +28,14 @@
 
 # import packages
 from hypatia.catalog import CatalogQuery
-from hypatia.query import Any
+from hypatia.query import Any, Gt, Lt
 from pyams_cache.beaker import get_cache
 from pyams_catalog.query import CatalogResultSet, or_
 from pyams_content.shared.common import WfSharedContent, register_content_type, SharedContent
 from pyams_utils.adapter import adapter_config, ContextAdapter
 from pyams_utils.list import unique
 from pyams_utils.registry import get_utility
+from pyams_utils.timezone import tztime
 from pyams_workflow.interfaces import IWorkflow
 from pyramid.events import subscriber
 from pyramid.threadlocal import get_current_registry
@@ -91,7 +94,7 @@
 class ViewQuery(ContextAdapter):
     """View query"""
 
-    def get_es_params(self, context):
+    def get_params(self, context):
         view = self.context
         catalog = get_utility(ICatalog)
         registry = get_current_registry()
@@ -100,6 +103,9 @@
         for workflow in registry.getAllUtilitiesRegisteredFor(IWorkflow):
             wf_params = or_(wf_params, Any(catalog['workflow_state'], workflow.published_states))
         params &= wf_params
+        now = tztime(datetime.utcnow())
+        params &= Lt(catalog['effective_date'], now)
+        params &= Gt(catalog['push_end_date'], now)
         for name, adapter in sorted(registry.getAdapters((view,), IViewQueryParamsExtension),
                                     key=lambda x: x[1].weight):
             new_params = adapter.get_params(context)
@@ -111,7 +117,7 @@
         view = self.context
         catalog = get_utility(ICatalog)
         registry = get_current_registry()
-        params = self.get_es_params(context)
+        params = self.get_params(context)
         items = CatalogResultSet(CatalogQuery(catalog).query(params,
                                                              sort_index=view.order_by,
                                                              reverse=view.reversed_order,