Add option to not check parent in "get_published" / "get_visible" methods
authorThierry Florac <thierry.florac@onf.fr>
Mon, 04 Dec 2017 15:26:42 +0100
changeset 48 caa4dfcc51ee
parent 47 31cbce6cb864
child 49 8ffebf1c77c2
Add option to not check parent in "get_published" / "get_visible" methods
src/pyams_workflow/content.py
src/pyams_workflow/interfaces/__init__.py
--- a/src/pyams_workflow/content.py	Sun Nov 26 10:17:30 2017 +0100
+++ b/src/pyams_workflow/content.py	Mon Dec 04 15:26:42 2017 +0100
@@ -154,11 +154,12 @@
         self._publication_expiration_date = None
         self.push_end_date = None
 
-    def is_published(self):
+    def is_published(self, check_parent=True):
         # check is parent is published
-        parent = get_parent(self.__parent__, IWorkflowPublicationSupport, allow_context=False)
-        if (parent is not None) and not IWorkflowPublicationInfo(parent).is_published():
-            return False
+        if check_parent:
+            parent = get_parent(self.__parent__, IWorkflowPublicationSupport, allow_context=False)
+            if (parent is not None) and not IWorkflowPublicationInfo(parent).is_published():
+                return False
         # associated workflow?
         workflow = IWorkflow(self.__parent__, None)
         if (workflow is not None) and not workflow.published_states:
@@ -173,7 +174,7 @@
                ((self.publication_expiration_date is None) or
                 (self.publication_expiration_date >= now))
 
-    def is_visible(self, request=None):
+    def is_visible(self, request=None, check_parent=True):
         # associated workflow?
         content = IWorkflowManagedContent(self.__parent__, None)
         if content is not None:
@@ -189,7 +190,7 @@
         else:
             if not request.has_permission(VIEW_PERMISSION, context=self.__parent__):
                 return False
-        return self.is_published()
+        return self.is_published(check_parent)
 
 
 WORKFLOW_CONTENT_KEY = 'pyams_workflow.content_info'
--- a/src/pyams_workflow/interfaces/__init__.py	Sun Nov 26 10:17:30 2017 +0100
+++ b/src/pyams_workflow/interfaces/__init__.py	Mon Dec 04 15:26:42 2017 +0100
@@ -467,10 +467,10 @@
     def reset(self):
         """Reset all publication info (used by clone features)"""
 
-    def is_published(self):
+    def is_published(self, check_parent=True):
         """Is the content published?"""
 
-    def is_visible(self, request=None):
+    def is_visible(self, request=None, check_parent=True):
         """Is the content visible?"""