Added preview support to portal context
authorThierry Florac <thierry.florac@onf.fr>
Thu, 15 Mar 2018 09:28:15 +0100
changeset 69 00694ea467e8
parent 68 6945c7f17308
child 70 68d0d7a99ce3
Added preview support to portal context
src/pyams_portal/views.py
--- a/src/pyams_portal/views.py	Sun Mar 11 11:23:36 2018 +0100
+++ b/src/pyams_portal/views.py	Thu Mar 15 09:28:15 2018 +0100
@@ -19,12 +19,15 @@
 from pyams_default_theme.layer import IPyAMSDefaultLayer
 from pyams_portal.interfaces import IPortalContext, IPortalPage, IPortalTemplateConfiguration, \
     IPortalPortletsConfiguration, IPortletRenderer, IPortlet
+from pyams_utils.interfaces import VIEW_SYSTEM_PERMISSION
+from pyams_workflow.interfaces import IWorkflowPublicationInfo
 
 # import packages
 from pyams_default_theme.page import BaseIndexPage
 from pyams_pagelet.pagelet import pagelet_config
 from pyams_template.template import template_config
 from pyramid.decorator import reify
+from pyramid.exceptions import NotFound
 
 
 @pagelet_config(name='', context=IPortalContext, layer=IPyAMSDefaultLayer)
@@ -32,6 +35,12 @@
 class PortalContextIndexPage(BaseIndexPage):
     """Portal context index page"""
 
+    def update(self):
+        wf_info = IWorkflowPublicationInfo(self.context, None)
+        if (wf_info is not None) and not wf_info.is_visible(self.request):
+            raise NotFound()
+        super(PortalContextIndexPage, self).update()
+
     @reify
     def page(self):
         return IPortalPage(self.context)
@@ -56,3 +65,13 @@
             return renderer()
         else:
             return ''
+
+
+@pagelet_config(name='preview.html', context=IPortalContext, layer=IPyAMSDefaultLayer,
+                permission=VIEW_SYSTEM_PERMISSION)
+class PortalContextPreviewPage(PortalContextIndexPage):
+    """Portal context preview page"""
+
+    def update(self):
+        # Bypass publication status in preview
+        super(PortalContextIndexPage, self).update()