Added preview page
authorThierry Florac <thierry.florac@onf.fr>
Thu, 15 Mar 2018 09:32:24 +0100
changeset 16 d2950d484bdf
parent 15 12e5bc30061a
child 17 5a8888d973b4
Added preview page
src/pyams_default_theme/page.py
--- a/src/pyams_default_theme/page.py	Thu Mar 15 09:31:00 2018 +0100
+++ b/src/pyams_default_theme/page.py	Thu Mar 15 09:32:24 2018 +0100
@@ -16,7 +16,10 @@
 # import standard library
 
 # import interfaces
+from pyams_content.features.preview.interfaces import IPreviewTarget
+from pyams_content.features.renderer.interfaces import IContentRenderer
 from pyams_default_theme.layer import IPyAMSDefaultLayer
+from pyams_utils.interfaces import VIEW_SYSTEM_PERMISSION
 
 # import packages
 from pyams_pagelet.pagelet import pagelet_config
@@ -28,3 +31,27 @@
 @template_config(template='templates/index.pt', layer=IPyAMSDefaultLayer)
 class BaseIndexPage(object):
     """Default base index page"""
+
+
+@pagelet_config(name='preview.html', context=IPreviewTarget, layer=IPyAMSDefaultLayer,
+                permission=VIEW_SYSTEM_PERMISSION)
+class PreviewPage(BaseIndexPage):
+    """Preview page"""
+
+    def __init__(self, context, request):
+        super(PreviewPage, self).__init__(context, request)
+        self.language = self.request.params.get('lang')
+        self.renderers = sorted(self.request.registry.getAdapters((self.context, self.request), IContentRenderer),
+                                key=lambda x: getattr(x[1], 'weight', 0))
+
+    def update(self):
+        super(PreviewPage, self).update()
+        for name, renderer in self.renderers:
+            renderer.language = self.language
+            renderer.update()
+
+    def render(self):
+        result = ''
+        for name, renderer in self.renderers:
+            result += renderer.render()
+        return result