src/pyams_content/shared/view/__init__.py
changeset 1134 35e8b9cd9070
parent 1121 852aa448da04
child 1162 d8d05f5c83ba
--- a/src/pyams_content/shared/view/__init__.py	Tue Nov 27 17:21:47 2018 +0100
+++ b/src/pyams_content/shared/view/__init__.py	Wed Nov 28 09:39:16 2018 +0100
@@ -18,7 +18,7 @@
 
 from hypatia.catalog import CatalogQuery
 from hypatia.interfaces import ICatalog
-from hypatia.query import Any, Gt, Lt
+from hypatia.query import Any, Gt, Lt, Eq
 from pyramid.events import subscriber
 from pyramid.threadlocal import get_current_registry
 from zope.interface import implementer, provider
@@ -66,6 +66,7 @@
     handle_header = False
     handle_description = False
 
+    select_context_path = FieldProperty(IWfView['select_context_path'])
     select_context_type = FieldProperty(IWfView['select_context_type'])
     selected_content_types = FieldProperty(IWfView['selected_content_types'])
     select_context_datatype = FieldProperty(IWfView['select_context_datatype'])
@@ -76,7 +77,7 @@
 
     @property
     def is_using_context(self):
-        if self.select_context_type:
+        if self.select_context_path or self.select_context_type:
             return True
         registry = get_global_registry()
         for name, adapter in registry.getAdapters((self,), IViewSettings):
@@ -86,6 +87,11 @@
                 return True
         return False
 
+    def get_content_path(self, context):
+        if self.select_context_path:
+            intids = get_utility(IIntIds)
+            return intids.queryId(context)
+
     def get_content_types(self, context):
         content_types = set()
         if self.select_context_type and IWfSharedContent.providedBy(context):
@@ -104,8 +110,8 @@
             data_types |= set(self.selected_datatypes)
         return list(data_types)
 
-    def get_results(self, context, sort_index=None, reverse=None,
-                    limit=None, start=0, length=999, ignore_cache=False, get_count=False):
+    def get_results(self, context, sort_index=None, reverse=None, limit=None,
+                    start=0, length=999, ignore_cache=False, get_count=False):
         results = _MARKER
         if not ignore_cache:
             # check for cache
@@ -191,6 +197,10 @@
         # activate search
         if do_search:
             params &= Gt(catalog['push_end_date'], now)
+            # check content path
+            content_path = view.get_content_path(context)
+            if content_path is not None:
+                params &= Eq(catalog['parents'], content_path)
             # check content types
             content_types = view.get_content_types(context)
             if content_types: