Moved view params settings to another package
authorThierry Florac <thierry.florac@onf.fr>
Tue, 08 Jan 2019 14:04:53 +0100
changeset 137 fc81a5fb2225
parent 136 68ae22131209
child 138 739f21526374
Moved view params settings to another package
src/pyams_content_es/component/theme.py
--- a/src/pyams_content_es/component/theme.py	Mon Jan 07 11:50:47 2019 +0100
+++ b/src/pyams_content_es/component/theme.py	Tue Jan 08 14:04:53 2019 +0100
@@ -12,19 +12,14 @@
 
 __docformat__ = 'restructuredtext'
 
-from elasticsearch_dsl import Q
 from zope.intid.interfaces import IIntIds
 
-from pyams_content.component.theme import ICollectionsInfo, ICollectionsTarget, ITagsManager
+from pyams_content.component.theme import ICollectionsInfo, ICollectionsTarget
 from pyams_content.component.theme.interfaces import ITagsInfo, ITagsTarget, IThemesInfo, IThemesTarget
-from pyams_content.shared.view.interfaces import IViewCollectionsSettings, IViewQueryEsParamsExtension, \
-    IViewTagsSettings, IViewThemesSettings, IViewUserQuery, IWfView
 from pyams_content_es.interfaces import IDocumentIndexInfo
-from pyams_content_es.shared.view import EsSearchFolderQuery
-from pyams_thesaurus.interfaces.thesaurus import IThesaurus
-from pyams_utils.adapter import ContextAdapter, adapter_config
+from pyams_utils.adapter import adapter_config
 from pyams_utils.list import unique
-from pyams_utils.registry import get_utility, query_utility
+from pyams_utils.registry import get_utility
 
 
 #
@@ -41,39 +36,6 @@
     }
 
 
-@adapter_config(name='tags', context=IWfView, provides=IViewQueryEsParamsExtension)
-class ViewTagsQueryEsParamsExtension(ContextAdapter):
-    """View tags query adapter """
-
-    weight = 60
-
-    def get_es_params(self, context, request=None):
-        settings = IViewTagsSettings(self.context)
-        tags = settings.get_tags_index(context)
-        if tags:
-            yield Q('terms', **{'tags': tags})
-
-
-@adapter_config(name='tag', context=EsSearchFolderQuery, provides=IViewUserQuery)
-class EsSearchFolderTagQuery(ContextAdapter):
-    """Search folder tag query for Elasticsearch"""
-
-    @staticmethod
-    def get_user_params(request):
-        tag = request.params.get('tag')
-        if tag:
-            manager = ITagsManager(request.root, None)
-            if manager is None:
-                raise StopIteration
-            thesaurus = query_utility(IThesaurus, name=manager.thesaurus_name)
-            if thesaurus is None:
-                raise StopIteration
-            term = thesaurus.terms.get(tag)
-            if term is not None:
-                intids = query_utility(IIntIds)
-                yield Q('term', **{'tags': intids.queryId(term)})
-
-
 #
 # Themes index
 #
@@ -103,19 +65,6 @@
     }
 
 
-@adapter_config(name='themes', context=IWfView, provides=IViewQueryEsParamsExtension)
-class ViewThemesQueryEsParamsExtension(ContextAdapter):
-    """View themes query adapter """
-
-    weight = 62
-
-    def get_es_params(self, context, request=None):
-        settings = IViewThemesSettings(self.context)
-        themes = settings.get_themes_index(context)
-        if themes:
-            yield Q('terms', **{'themes.terms': themes})
-
-
 #
 # Collections index
 #
@@ -128,16 +77,3 @@
     return {
         'collections': [intids.register(tag) for tag in unique(collections)]
     }
-
-
-@adapter_config(name='collections', context=IWfView, provides=IViewQueryEsParamsExtension)
-class ViewCollectionsQueryEsParamsExtension(ContextAdapter):
-    """View collections query adapter """
-
-    weight = 64
-
-    def get_es_params(self, context, request=None):
-        settings = IViewCollectionsSettings(self.context)
-        collections = settings.get_collections_index(context)
-        if collections:
-            yield Q('terms', **{'collections': collections})