Use new view's "get_content_types" method
authorThierry Florac <thierry.florac@onf.fr>
Thu, 22 Feb 2018 10:15:31 +0100
changeset 49 78867d93d490
parent 48 4575175f6458
child 50 7cc2aec2876c
Use new view's "get_content_types" method
src/pyams_content_es/component/view.py
--- a/src/pyams_content_es/component/view.py	Sun Feb 18 12:45:07 2018 +0100
+++ b/src/pyams_content_es/component/view.py	Thu Feb 22 10:15:31 2018 +0100
@@ -39,15 +39,21 @@
     def get_es_params(self, context):
         view = self.context
         registry = get_current_registry()
-        params = Q('terms', **{'content_type': view.selected_content_types})
+        # check publication dates
+        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'}))
+        # check content types
+        content_types = view.get_content_types(context)
+        if content_types:
+            params &= Q('terms', **{'content_type': content_types})
+        # check workflow states
         wf_params = []
         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'}))
+        # check custom extensions
         for name, adapter in sorted(registry.getAdapters((view,), IViewQueryEsParamsExtension),
                                     key=lambda x: x[1].weight):
             new_params = adapter.get_es_params(context)