src/pyams_content_es/shared/view/theme.py
changeset 159 bc34f44a9711
parent 138 739f21526374
child 171 2c8a4c796d1e
equal deleted inserted replaced
158:4ae24ec1db78 159:bc34f44a9711
    13 __docformat__ = 'restructuredtext'
    13 __docformat__ = 'restructuredtext'
    14 
    14 
    15 from elasticsearch_dsl import Q
    15 from elasticsearch_dsl import Q
    16 from zope.intid.interfaces import IIntIds
    16 from zope.intid.interfaces import IIntIds
    17 
    17 
    18 from pyams_content.component.theme import ITagsManager
    18 from pyams_content.component.theme import ICollectionsManager, ITagsManager
    19 from pyams_content.shared.view.interfaces import IViewCollectionsSettings, IViewQueryEsParamsExtension, \
    19 from pyams_content.shared.view.interfaces import IViewCollectionsSettings, \
    20     IViewTagsSettings, IViewThemesSettings, IViewUserQuery, IWfView
    20     IViewQueryEsParamsExtension, IViewTagsSettings, IViewThemesSettings, IViewUserQuery, IWfView
    21 from pyams_content_es.shared.view import EsSearchFolderQuery
    21 from pyams_content_es.shared.view import EsSearchFolderQuery
    22 from pyams_thesaurus.interfaces.thesaurus import IThesaurus
    22 from pyams_thesaurus.interfaces.thesaurus import IThesaurus
    23 from pyams_utils.adapter import ContextAdapter, adapter_config
    23 from pyams_utils.adapter import ContextAdapter, adapter_config
    24 from pyams_utils.registry import query_utility
    24 from pyams_utils.registry import query_utility
    25 
    25 
    97         collections = settings.get_collections_index(context)
    97         collections = settings.get_collections_index(context)
    98         if collections:
    98         if collections:
    99             yield Q('terms', **{'collections': collections})
    99             yield Q('terms', **{'collections': collections})
   100         elif settings.select_context_collections:
   100         elif settings.select_context_collections:
   101             yield None
   101             yield None
       
   102 
       
   103 
       
   104 @adapter_config(name='collection', context=EsSearchFolderQuery, provides=IViewUserQuery)
       
   105 class EsSearchFolderCollectionQuery(ContextAdapter):
       
   106     """Search folder collection query for Elasticsearch"""
       
   107 
       
   108     @staticmethod
       
   109     def get_user_params(request):
       
   110         collection = request.params.get('collection')
       
   111         if collection:
       
   112             manager = ICollectionsManager(request.root, None)
       
   113             if manager is None:
       
   114                 raise StopIteration
       
   115             thesaurus = query_utility(IThesaurus, name=manager.thesaurus_name)
       
   116             if thesaurus is None:
       
   117                 raise StopIteration
       
   118             term = thesaurus.terms.get(collection)
       
   119             if term is not None:
       
   120                 intids = query_utility(IIntIds)
       
   121                 yield Q('term', **{'collections': intids.queryId(term)})