# HG changeset patch # User Thierry Florac # Date 1519290931 -3600 # Node ID 78867d93d4904e2f717a59504287bbdcb6fd7fc6 # Parent 4575175f645819a1369624a9c740ad19b90d5913 Use new view's "get_content_types" method diff -r 4575175f6458 -r 78867d93d490 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)