Refactored paragraphs preview with new generic class
authorThierry Florac <thierry.florac@onf.fr>
Fri, 02 Mar 2018 15:35:17 +0100
changeset 432 a068d20dc9ae
parent 431 a162e9f348f7
child 433 76a597a42c19
Refactored paragraphs preview with new generic class
src/pyams_content/component/gallery/zmi/paragraph.py
src/pyams_content/component/illustration/zmi/paragraph.py
src/pyams_content/component/paragraph/zmi/contact.py
src/pyams_content/component/paragraph/zmi/header.py
src/pyams_content/component/paragraph/zmi/keypoint.py
--- a/src/pyams_content/component/gallery/zmi/paragraph.py	Fri Mar 02 15:02:52 2018 +0100
+++ b/src/pyams_content/component/gallery/zmi/paragraph.py	Fri Mar 02 15:35:17 2018 +0100
@@ -33,6 +33,7 @@
 from pyams_content.component.gallery.paragraph import Gallery
 from pyams_content.component.paragraph.zmi import BaseParagraphAJAXAddForm, BaseParagraphAJAXEditForm, \
     BaseParagraphAddMenu, BaseParagraphPropertiesEditForm
+from pyams_content.features.renderer.zmi import BaseRenderedContentPreview
 from pyams_content.features.renderer.zmi.widget import RendererFieldWidget
 from pyams_content.shared.common.zmi import WfSharedContentPermissionMixin
 from pyams_pagelet.pagelet import pagelet_config
@@ -40,7 +41,7 @@
 from pyams_template.template import template_config
 from pyams_utils.adapter import adapter_config
 from pyams_utils.url import absolute_url
-from pyams_viewlet.viewlet import viewlet_config, BaseContentProvider
+from pyams_viewlet.viewlet import viewlet_config
 from pyams_zmi.form import AdminDialogAddForm, InnerAdminDisplayForm
 from pyramid.view import view_config
 from z3c.form import field, button
@@ -184,26 +185,9 @@
 
 
 #
-# Gallery paragraph summary
+# Gallery paragraph preview
 #
 
 @adapter_config(context=(IGalleryParagraph, IPyAMSLayer), provides=IParagraphPreview)
-class GalleryParagraphPreview(BaseContentProvider):
+class GalleryParagraphPreview(BaseRenderedContentPreview):
     """Gallery preview"""
-
-    def __init__(self, context, request):
-        super(GalleryParagraphPreview, self).__init__(context, request)
-        self.renderer = self.context.get_renderer(request)
-
-    language = None
-
-    def update(self):
-        if self.renderer is not None:
-            self.renderer.language = self.language
-            self.renderer.update()
-
-    def render(self):
-        if self.renderer is not None:
-            return self.renderer.render()
-        else:
-            return ''
--- a/src/pyams_content/component/illustration/zmi/paragraph.py	Fri Mar 02 15:02:52 2018 +0100
+++ b/src/pyams_content/component/illustration/zmi/paragraph.py	Fri Mar 02 15:35:17 2018 +0100
@@ -33,10 +33,11 @@
 from pyams_content.component.illustration.paragraph import Illustration
 from pyams_content.component.paragraph.zmi import BaseParagraphAJAXAddForm, BaseParagraphAJAXEditForm, \
     BaseParagraphAddMenu, BaseParagraphPropertiesEditForm
+from pyams_content.features.renderer.zmi import BaseRenderedContentPreview
 from pyams_content.features.renderer.zmi.widget import RendererFieldWidget
 from pyams_pagelet.pagelet import pagelet_config
 from pyams_utils.adapter import adapter_config
-from pyams_viewlet.viewlet import viewlet_config, BaseContentProvider
+from pyams_viewlet.viewlet import viewlet_config
 from pyams_zmi.form import AdminDialogAddForm
 from pyramid.view import view_config
 from z3c.form import field, button
@@ -190,22 +191,5 @@
 #
 
 @adapter_config(context=(IIllustrationParagraph, IPyAMSLayer), provides=IParagraphPreview)
-class IllustrationPreview(BaseContentProvider):
+class IllustrationPreview(BaseRenderedContentPreview):
     """Illustration preview"""
-
-    def __init__(self, context, request):
-        super(IllustrationPreview, self).__init__(context, request)
-        self.renderer = self.context.get_renderer()
-
-    language = None
-
-    def update(self):
-        if self.renderer is not None:
-            self.renderer.language = self.language
-            self.renderer.update()
-
-    def render(self):
-        if self.renderer is not None:
-            return self.renderer.render()
-        else:
-            return ''
--- a/src/pyams_content/component/paragraph/zmi/contact.py	Fri Mar 02 15:02:52 2018 +0100
+++ b/src/pyams_content/component/paragraph/zmi/contact.py	Fri Mar 02 15:35:17 2018 +0100
@@ -32,10 +32,11 @@
 from pyams_content.component.paragraph.contact import ContactParagraph
 from pyams_content.component.paragraph.zmi import BaseParagraphAddMenu, BaseParagraphAJAXAddForm, \
     BaseParagraphPropertiesEditForm, BaseParagraphAJAXEditForm
+from pyams_content.features.renderer.zmi import BaseRenderedContentPreview
 from pyams_content.features.renderer.zmi.widget import RendererFieldWidget
 from pyams_pagelet.pagelet import pagelet_config
 from pyams_utils.adapter import adapter_config
-from pyams_viewlet.viewlet import viewlet_config, BaseContentProvider
+from pyams_viewlet.viewlet import viewlet_config
 from pyams_zmi.form import AdminDialogAddForm
 from pyramid.view import view_config
 from z3c.form import field, button
@@ -170,22 +171,8 @@
 #
 
 @adapter_config(context=(IContactParagraph, IPyAMSLayer), provides=IParagraphPreview)
-class ContactParagraphPreview(BaseContentProvider):
+class ContactParagraphPreview(BaseRenderedContentPreview):
     """Contact paragraph preview"""
 
-    def __init__(self, context, request):
-        super(ContactParagraphPreview, self).__init__(context, request)
-        self.renderer = self.context.get_renderer()
-
-    language = None
-
-    def update(self):
-        if self.renderer is not None:
-            self.renderer.language = self.language
-            self.renderer.update()
-
-    def render(self):
-        if self.renderer is not None:
-            return self.renderer.render()
-        else:
-            return ''
+    context_attrs = ('name', 'photo', 'gps_location', 'address')
+    i18n_context_attrs = ('title', 'charge', )
--- a/src/pyams_content/component/paragraph/zmi/header.py	Fri Mar 02 15:02:52 2018 +0100
+++ b/src/pyams_content/component/paragraph/zmi/header.py	Fri Mar 02 15:35:17 2018 +0100
@@ -31,10 +31,11 @@
 from pyams_content.component.paragraph.header import HeaderParagraph
 from pyams_content.component.paragraph.zmi import BaseParagraphAJAXAddForm, BaseParagraphAJAXEditForm, \
     BaseParagraphAddMenu, BaseParagraphPropertiesEditForm
+from pyams_content.features.renderer.zmi import BaseRenderedContentPreview
 from pyams_content.features.renderer.zmi.widget import RendererFieldWidget
 from pyams_pagelet.pagelet import pagelet_config
 from pyams_utils.adapter import adapter_config
-from pyams_viewlet.viewlet import viewlet_config, BaseContentProvider
+from pyams_viewlet.viewlet import viewlet_config
 from pyams_zmi.form import AdminDialogAddForm
 from pyramid.view import view_config
 from z3c.form import field, button
@@ -172,22 +173,7 @@
 #
 
 @adapter_config(context=(IHeaderParagraph, IPyAMSLayer), provides=IParagraphPreview)
-class HeaderParagraphPreview(BaseContentProvider):
+class HeaderParagraphPreview(BaseRenderedContentPreview):
     """Header paragraph preview"""
 
-    def __init__(self, context, request):
-        super(HeaderParagraphPreview, self).__init__(context, request)
-        self.renderer = self.context.get_renderer()
-
-    language = None
-
-    def update(self):
-        if self.renderer is not None:
-            self.renderer.language = self.language
-            self.renderer.update()
-
-    def render(self):
-        if self.renderer is not None:
-            return self.renderer.render()
-        else:
-            return ''
+    i18n_context_attrs = ('header', )
--- a/src/pyams_content/component/paragraph/zmi/keypoint.py	Fri Mar 02 15:02:52 2018 +0100
+++ b/src/pyams_content/component/paragraph/zmi/keypoint.py	Fri Mar 02 15:35:17 2018 +0100
@@ -31,11 +31,11 @@
 from pyams_content.component.paragraph.keypoint import KeypointsParagraph
 from pyams_content.component.paragraph.zmi import BaseParagraphAJAXAddForm, BaseParagraphAJAXEditForm, \
     BaseParagraphAddMenu, BaseParagraphPropertiesEditForm
+from pyams_content.features.renderer.zmi import BaseRenderedContentPreview
 from pyams_content.features.renderer.zmi.widget import RendererFieldWidget
 from pyams_pagelet.pagelet import pagelet_config
-from pyams_template.template import template_config
 from pyams_utils.adapter import adapter_config
-from pyams_viewlet.viewlet import viewlet_config, BaseContentProvider
+from pyams_viewlet.viewlet import viewlet_config
 from pyams_zmi.form import AdminDialogAddForm
 from pyramid.view import view_config
 from z3c.form import field, button
@@ -173,22 +173,7 @@
 #
 
 @adapter_config(context=(IKeypointsParagraph, IPyAMSLayer), provides=IParagraphPreview)
-class KeypointsParagraphPreview(BaseContentProvider):
+class KeypointsParagraphPreview(BaseRenderedContentPreview):
     """Key points paragraph preview"""
 
-    def __init__(self, context, request):
-        super(KeypointsParagraphPreview, self).__init__(context, request)
-        self.renderer = self.context.get_renderer()
-
-    language = None
-
-    def update(self):
-        if self.renderer is not None:
-            self.renderer.language = self.language
-            self.renderer.update()
-
-    def render(self):
-        if self.renderer is not None:
-            return self.renderer.render()
-        else:
-            return ''
+    i18n_context_attrs = ('body', )