src/pyams_content/component/paragraph/video.py
changeset 439 2a61d39de0fc
parent 407 0ef5de2d5674
child 555 8e8a14452567
--- a/src/pyams_content/component/paragraph/video.py	Fri Mar 02 17:54:01 2018 +0100
+++ b/src/pyams_content/component/paragraph/video.py	Sun Mar 04 16:36:30 2018 +0100
@@ -19,7 +19,8 @@
 from pyams_content.component.extfile.interfaces import IExtFileContainerTarget
 from pyams_content.component.links.interfaces import ILinkContainerTarget
 from pyams_content.component.paragraph.interfaces import IParagraphFactory
-from pyams_content.component.paragraph.interfaces.video import IVideoParagraph, VIDEO_PARAGRAPH_TYPE
+from pyams_content.component.paragraph.interfaces.video import IVideoParagraph, VIDEO_PARAGRAPH_TYPE, \
+    VIDEO_PARAGRAPH_RENDERERS
 from pyams_content.features.checker.interfaces import IContentChecker, MISSING_VALUE, MISSING_LANG_VALUE
 from pyams_i18n.interfaces import II18nManager, INegotiator, II18n
 from zope.lifecycleevent.interfaces import IObjectAddedEvent, IObjectModifiedEvent
@@ -27,19 +28,23 @@
 # import packages
 from pyams_content.component.paragraph import BaseParagraph, BaseParagraphContentChecker, BaseParagraphFactory
 from pyams_content.component.paragraph.html import check_associations
+from pyams_content.features.renderer import RenderedContentMixin, IContentRenderer
 from pyams_file.property import FileProperty
 from pyams_utils.adapter import adapter_config
 from pyams_utils.registry import utility_config, get_utility
+from pyams_utils.request import check_request
 from pyams_utils.traversing import get_parent
+from pyams_utils.vocabulary import vocabulary_config
 from pyramid.events import subscriber
 from zope.interface import implementer
 from zope.schema.fieldproperty import FieldProperty
+from zope.schema.vocabulary import SimpleVocabulary, SimpleTerm
 
 from pyams_content import _
 
 
 @implementer(IVideoParagraph, IExtFileContainerTarget, ILinkContainerTarget)
-class VideoParagraph(BaseParagraph):
+class VideoParagraph(RenderedContentMixin, BaseParagraph):
     """Video paragraph class"""
 
     icon_class = 'fa-film'
@@ -49,6 +54,7 @@
     description = FieldProperty(IVideoParagraph['description'])
     author = FieldProperty(IVideoParagraph['author'])
     data = FileProperty(IVideoParagraph['data'])
+    renderer = FieldProperty(IVideoParagraph['renderer'])
 
 
 @utility_config(name=VIDEO_PARAGRAPH_TYPE, provides=IParagraphFactory)
@@ -102,3 +108,19 @@
             if not value:
                 output.append(translate(MISSING_VALUE).format(field=translate(IVideoParagraph[attr].title)))
         return output
+
+
+@vocabulary_config(name=VIDEO_PARAGRAPH_RENDERERS)
+class VideoParagraphRendererVocabulary(SimpleVocabulary):
+    """Video paragraph renderers vocabulary"""
+
+    def __init__(self, context=None):
+        request = check_request()
+        translate = request.localizer.translate
+        registry = request.registry
+        if not IVideoParagraph.providedBy(context):
+            context = VideoParagraph()
+        terms = [SimpleTerm(name, title=translate(adapter.label))
+                 for name, adapter in sorted(registry.getAdapters((context, request), IContentRenderer),
+                                             key=lambda x: x[1].weight)]
+        super(VideoParagraphRendererVocabulary, self).__init__(terms)