Added gallery paragraph summary
authorThierry Florac <thierry.florac@onf.fr>
Wed, 13 Sep 2017 15:57:49 +0200
changeset 163 bd68fac5a89a
parent 162 fc3266e6a510
child 164 826753ab9e52
Added gallery paragraph summary
src/pyams_content/component/gallery/zmi/paragraph.py
--- a/src/pyams_content/component/gallery/zmi/paragraph.py	Wed Sep 13 15:57:18 2017 +0200
+++ b/src/pyams_content/component/gallery/zmi/paragraph.py	Wed Sep 13 15:57:49 2017 +0200
@@ -16,9 +16,10 @@
 # import standard library
 
 # import interfaces
-from pyams_content.component.gallery.interfaces import IGalleryParagraph, IBaseGallery
+from pyams_content.component.gallery.interfaces import IGalleryParagraph, IBaseGallery, IGalleryRenderer
 from pyams_content.component.gallery.zmi.interfaces import IGalleryImagesView
-from pyams_content.component.paragraph.interfaces import IParagraphContainerTarget, IParagraphContainer
+from pyams_content.component.paragraph.interfaces import IParagraphContainerTarget, IParagraphContainer, \
+    IParagraphSummary
 from pyams_content.component.paragraph.zmi.interfaces import IParagraphInnerEditor
 from pyams_content.interfaces import MANAGE_CONTENT_PERMISSION
 from pyams_content.shared.common.interfaces import IWfSharedContent
@@ -39,7 +40,7 @@
 from pyams_template.template import template_config
 from pyams_utils.adapter import adapter_config
 from pyams_utils.traversing import get_parent
-from pyams_viewlet.viewlet import viewlet_config
+from pyams_viewlet.viewlet import viewlet_config, BaseContentProvider
 from pyams_zmi.form import AdminDialogAddForm, AdminDialogEditForm, InnerAdminDisplayForm
 from pyramid.view import view_config
 from z3c.form import field, button
@@ -178,3 +179,25 @@
 #
 # Gallery paragraph summary
 #
+
+@adapter_config(context=(IGalleryParagraph, IPyAMSLayer), provides=IParagraphSummary)
+class GalleryParagraphSummary(BaseContentProvider):
+    """Gallery summary"""
+
+    def __init__(self, context, request):
+        super(GalleryParagraphSummary, self).__init__(context, request)
+        self.renderer = request.registry.queryMultiAdapter((context, request), IGalleryRenderer,
+                                                           name=self.context.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 ''