Add renderers to video paragraphs
authorThierry Florac <thierry.florac@onf.fr>
Fri, 25 May 2018 08:06:07 +0200
changeset 31 566d98116bf2
parent 30 bca2dd39ef7f
child 32 f0b28eb0bdf0
Add renderers to video paragraphs
src/pyams_default_theme/component/video/__init__.py
src/pyams_default_theme/component/video/templates/video-default.pt
--- a/src/pyams_default_theme/component/video/__init__.py	Fri May 25 08:05:52 2018 +0200
+++ b/src/pyams_default_theme/component/video/__init__.py	Fri May 25 08:06:07 2018 +0200
@@ -16,5 +16,49 @@
 # import standard library
 
 # import interfaces
+from pyams_content.component.video.interfaces import IExternalVideoParagraph, IExternalVideoRenderer
+from pyams_content.features.renderer.interfaces import IContentRenderer
+from pyams_skin.layer import IPyAMSLayer
 
 # import packages
+from pyams_content.features.renderer.skin import BaseContentRenderer
+from pyams_template.template import template_config
+from pyams_utils.adapter import adapter_config
+from pyams_utils.registry import get_current_registry
+
+from pyams_default_theme import _
+
+
+#
+# External video paragraph default renderer
+#
+
+@adapter_config(name='default', context=(IExternalVideoParagraph, IPyAMSLayer), provides=IContentRenderer)
+@template_config(template='templates/video-default.pt', layer=IPyAMSLayer)
+class ExternalVideoParagraphDefaultRenderer(BaseContentRenderer):
+    """external video paragraph default renderer"""
+
+    label = _("Default video renderer")
+
+    i18n_context_attrs = ('title', 'body', 'description')
+
+    video_renderer = None
+
+    def __init__(self, context, request):
+        super(ExternalVideoParagraphDefaultRenderer, self).__init__(context, request)
+        provider = context.get_provider()
+        if provider is not None:
+            registry = get_current_registry()
+            self.video_renderer = registry.queryMultiAdapter((context.settings, request), IExternalVideoRenderer)
+
+    def update(self):
+        super(ExternalVideoParagraphDefaultRenderer, self).update()
+        renderer = self.video_renderer
+        if renderer is not None:
+            renderer.update()
+
+    def render_video(self):
+        renderer = self.video_renderer
+        if not renderer:
+            return ''
+        return renderer.render()
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/pyams_default_theme/component/video/templates/video-default.pt	Fri May 25 08:06:07 2018 +0200
@@ -0,0 +1,7 @@
+<h3 tal:condition="view.title"
+	tal:content="view.title">title</h3>
+<div tal:condition="view.body"
+	 tal:content="structure view.body">body</div>
+<div tal:condition="view.description"
+	 tal:content="structure extension:html(view.description)">Description</div>
+<tal:var replace="structure view.render_video()" />