src/pyams_content/shared/view/theme.py
changeset 1389 1485db1e2b5e
parent 1240 921ff38f1aae
child 1428 48c1ee485dc0
--- a/src/pyams_content/shared/view/theme.py	Wed Jun 24 12:07:40 2020 +0200
+++ b/src/pyams_content/shared/view/theme.py	Fri Jun 26 12:54:13 2020 +0200
@@ -19,12 +19,13 @@
 from zope.intid.interfaces import IIntIds
 from zope.schema.fieldproperty import FieldProperty
 
-from pyams_content.component.theme import ICollectionsInfo, ITagsManager
+from pyams_content.component.theme import ICollectionsInfo, ICollectionsManager, ITagsManager
 from pyams_content.component.theme.interfaces import ITagsInfo, IThemesInfo
 from pyams_content.features.search import SearchFolderQuery
-from pyams_content.shared.view.interfaces import IViewCollectionsSettings, IViewQueryParamsExtension, IViewSettings, \
-    IViewTagsSettings, IViewThemesSettings, IViewUserQuery, IWfView, VIEW_COLLECTIONS_SETTINGS_KEY, \
-    VIEW_TAGS_SETTINGS_KEY, VIEW_THEMES_SETTINGS_KEY
+from pyams_content.shared.view.interfaces import IViewCollectionsSettings, \
+    IViewQueryParamsExtension, IViewSettings, IViewTagsSettings, IViewThemesSettings, \
+    IViewUserQuery, IWfView, VIEW_COLLECTIONS_SETTINGS_KEY, VIEW_TAGS_SETTINGS_KEY, \
+    VIEW_THEMES_SETTINGS_KEY
 from pyams_thesaurus.interfaces.thesaurus import IThesaurus
 from pyams_utils.adapter import ContextAdapter, adapter_config, get_annotation_adapter
 from pyams_utils.factory import factory_config
@@ -215,3 +216,24 @@
             yield Any(catalog['collections'], collections)
         elif settings.select_context_collections:
             yield None
+
+
+@adapter_config(name='collections', context=SearchFolderQuery, provides=IViewUserQuery)
+class SearchFolderCollectionQuery(ContextAdapter):
+    """Search folder collections query"""
+
+    @staticmethod
+    def get_user_params(request):
+        collection = request.params.get('collection')
+        if collection:
+            manager = ICollectionsManager(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(collection)
+            if term is not None:
+                catalog = get_utility(ICatalog)
+                intids = query_utility(IIntIds)
+                yield Any(catalog['collections'], (intids.queryId(term),))