Added generic rendered content previewer
authorThierry Florac <thierry.florac@onf.fr>
Fri, 02 Mar 2018 15:35:45 +0100
changeset 433 76a597a42c19
parent 432 a068d20dc9ae
child 434 a1c31d22e042
Added generic rendered content previewer
src/pyams_content/features/renderer/zmi/__init__.py
--- a/src/pyams_content/features/renderer/zmi/__init__.py	Fri Mar 02 15:35:17 2018 +0100
+++ b/src/pyams_content/features/renderer/zmi/__init__.py	Fri Mar 02 15:35:45 2018 +0100
@@ -9,7 +9,6 @@
 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
 # FOR A PARTICULAR PURPOSE.
 #
-from pyams_i18n.interfaces import II18n
 
 __docformat__ = 'restructuredtext'
 
@@ -19,6 +18,7 @@
 # import interfaces
 from pyams_content.features.renderer.interfaces import IRenderedContent, IContentRenderer, IRendererSettings
 from pyams_content.interfaces import MANAGE_CONTENT_PERMISSION
+from pyams_i18n.interfaces import II18n
 from pyams_skin.layer import IPyAMSLayer
 
 # import packages
@@ -35,6 +35,44 @@
 from pyams_content import _
 
 
+#
+# Base rendered content preview
+#
+
+class BaseRenderedContentPreview(BaseContentProvider):
+    """Base renderer preview"""
+
+    language = None
+    context_attrs = ()
+    i18n_context_attrs = ()
+
+    def __init__(self, context, request):
+        super(BaseRenderedContentPreview, self).__init__(context, request)
+        self.renderer = self.context.get_renderer()
+
+    def update(self):
+        renderer = self.renderer
+        if renderer is not None:
+            renderer.language = self.language
+            for attr in self.context_attrs:
+                setattr(renderer, attr, getattr(self.context, attr, None))
+            if self.i18n_context_attrs:
+                i18n = II18n(self.context, None)
+                if i18n is not None:
+                    for attr in self.i18n_context_attrs:
+                        setattr(renderer, attr, i18n.get_attribute(attr, lang=self.language, request=self.request))
+            renderer.update()
+
+    def render(self):
+        if self.renderer is None:
+            return ''
+        return self.renderer.render()
+
+
+#
+# Base content renderer
+#
+
 @implementer(IContentRenderer)
 class BaseContentRenderer(ContextRequestAdapter):
     """Base content renderer"""
@@ -81,36 +119,6 @@
     """Renderer properties edit form, JSON renderer"""
 
 
-class BaseRendererPreview(BaseContentProvider):
-    """Base renderer preview"""
-
-    language = None
-    context_attrs = ()
-    i18n_context_attrs = ()
-
-    def __init__(self, context, request):
-        super(BaseRendererPreview, self).__init__(context, request)
-        self.renderer = self.context.get_renderer()
-
-    def update(self):
-        renderer = self.renderer
-        if renderer is not None:
-            renderer.language = self.language
-            for attr in self.context_attrs:
-                setattr(renderer, attr, getattr(self.context, attr, None))
-            if self.i18n_context_attrs:
-                i18n = II18n(self.context, None)
-                if i18n is not None:
-                    for attr in self.i18n_context_attrs:
-                        setattr(renderer, attr, i18n.get_attribute(attr, lang=self.language, request=self.request))
-            renderer.update()
-
-    def render(self):
-        if self.renderer is None:
-            return ''
-        return self.renderer.render()
-
-
 #
 # Default common renderers
 #