# HG changeset patch # User Thierry Florac # Date 1528721879 -7200 # Node ID 7ef9d814b2d28fc0de7614b35e7d497f2ce438f6 # Parent fc04752a10a50f478364ec7ad82af7d0316d26ae Added internal references params extension diff -r fc04752a10a5 -r 7ef9d814b2d2 src/pyams_content_es/component/reference.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/pyams_content_es/component/reference.py Mon Jun 11 14:57:59 2018 +0200 @@ -0,0 +1,38 @@ +# +# Copyright (c) 2008-2018 Thierry Florac +# All Rights Reserved. +# +# This software is subject to the provisions of the Zope Public License, +# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution. +# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED +# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS +# FOR A PARTICULAR PURPOSE. +# + +__docformat__ = 'restructuredtext' + + +# import standard library + +# import interfaces +from elasticsearch_dsl import Q +from pyams_content.shared.view.interfaces import IWfView, IViewQueryEsParamsExtension, IViewInternalReferencesSettings +from zope.intid.interfaces import IIntIds + +# import packages +from pyams_utils.adapter import adapter_config, ContextAdapter +from pyams_utils.registry import get_utility + + +@adapter_config(name='references', context=IWfView, provides=IViewQueryEsParamsExtension) +class ViewInternalReferencesQueryEsParamsExtension(ContextAdapter): + """View internal references query params extension""" + + weight = 50 + + def get_es_params(self, context): + settings = IViewInternalReferencesSettings(self.context) + if settings.exclude_context: + intids = get_utility(IIntIds) + return Q('bool', must_not=Q('term', internal_id=intids.register(context)))