src/pyams_content/component/paragraph/video.py
changeset 439 2a61d39de0fc
parent 407 0ef5de2d5674
child 555 8e8a14452567
equal deleted inserted replaced
438:117089568313 439:2a61d39de0fc
    17 
    17 
    18 # import interfaces
    18 # import interfaces
    19 from pyams_content.component.extfile.interfaces import IExtFileContainerTarget
    19 from pyams_content.component.extfile.interfaces import IExtFileContainerTarget
    20 from pyams_content.component.links.interfaces import ILinkContainerTarget
    20 from pyams_content.component.links.interfaces import ILinkContainerTarget
    21 from pyams_content.component.paragraph.interfaces import IParagraphFactory
    21 from pyams_content.component.paragraph.interfaces import IParagraphFactory
    22 from pyams_content.component.paragraph.interfaces.video import IVideoParagraph, VIDEO_PARAGRAPH_TYPE
    22 from pyams_content.component.paragraph.interfaces.video import IVideoParagraph, VIDEO_PARAGRAPH_TYPE, \
       
    23     VIDEO_PARAGRAPH_RENDERERS
    23 from pyams_content.features.checker.interfaces import IContentChecker, MISSING_VALUE, MISSING_LANG_VALUE
    24 from pyams_content.features.checker.interfaces import IContentChecker, MISSING_VALUE, MISSING_LANG_VALUE
    24 from pyams_i18n.interfaces import II18nManager, INegotiator, II18n
    25 from pyams_i18n.interfaces import II18nManager, INegotiator, II18n
    25 from zope.lifecycleevent.interfaces import IObjectAddedEvent, IObjectModifiedEvent
    26 from zope.lifecycleevent.interfaces import IObjectAddedEvent, IObjectModifiedEvent
    26 
    27 
    27 # import packages
    28 # import packages
    28 from pyams_content.component.paragraph import BaseParagraph, BaseParagraphContentChecker, BaseParagraphFactory
    29 from pyams_content.component.paragraph import BaseParagraph, BaseParagraphContentChecker, BaseParagraphFactory
    29 from pyams_content.component.paragraph.html import check_associations
    30 from pyams_content.component.paragraph.html import check_associations
       
    31 from pyams_content.features.renderer import RenderedContentMixin, IContentRenderer
    30 from pyams_file.property import FileProperty
    32 from pyams_file.property import FileProperty
    31 from pyams_utils.adapter import adapter_config
    33 from pyams_utils.adapter import adapter_config
    32 from pyams_utils.registry import utility_config, get_utility
    34 from pyams_utils.registry import utility_config, get_utility
       
    35 from pyams_utils.request import check_request
    33 from pyams_utils.traversing import get_parent
    36 from pyams_utils.traversing import get_parent
       
    37 from pyams_utils.vocabulary import vocabulary_config
    34 from pyramid.events import subscriber
    38 from pyramid.events import subscriber
    35 from zope.interface import implementer
    39 from zope.interface import implementer
    36 from zope.schema.fieldproperty import FieldProperty
    40 from zope.schema.fieldproperty import FieldProperty
       
    41 from zope.schema.vocabulary import SimpleVocabulary, SimpleTerm
    37 
    42 
    38 from pyams_content import _
    43 from pyams_content import _
    39 
    44 
    40 
    45 
    41 @implementer(IVideoParagraph, IExtFileContainerTarget, ILinkContainerTarget)
    46 @implementer(IVideoParagraph, IExtFileContainerTarget, ILinkContainerTarget)
    42 class VideoParagraph(BaseParagraph):
    47 class VideoParagraph(RenderedContentMixin, BaseParagraph):
    43     """Video paragraph class"""
    48     """Video paragraph class"""
    44 
    49 
    45     icon_class = 'fa-film'
    50     icon_class = 'fa-film'
    46     icon_hint = _("Video")
    51     icon_hint = _("Video")
    47 
    52 
    48     body = FieldProperty(IVideoParagraph['body'])
    53     body = FieldProperty(IVideoParagraph['body'])
    49     description = FieldProperty(IVideoParagraph['description'])
    54     description = FieldProperty(IVideoParagraph['description'])
    50     author = FieldProperty(IVideoParagraph['author'])
    55     author = FieldProperty(IVideoParagraph['author'])
    51     data = FileProperty(IVideoParagraph['data'])
    56     data = FileProperty(IVideoParagraph['data'])
       
    57     renderer = FieldProperty(IVideoParagraph['renderer'])
    52 
    58 
    53 
    59 
    54 @utility_config(name=VIDEO_PARAGRAPH_TYPE, provides=IParagraphFactory)
    60 @utility_config(name=VIDEO_PARAGRAPH_TYPE, provides=IParagraphFactory)
    55 class VideoParagraphFactory(BaseParagraphFactory):
    61 class VideoParagraphFactory(BaseParagraphFactory):
    56     """Video paragraph factory"""
    62     """Video paragraph factory"""
   100         for attr in ('author', 'data'):
   106         for attr in ('author', 'data'):
   101             value = getattr(self.context, attr)
   107             value = getattr(self.context, attr)
   102             if not value:
   108             if not value:
   103                 output.append(translate(MISSING_VALUE).format(field=translate(IVideoParagraph[attr].title)))
   109                 output.append(translate(MISSING_VALUE).format(field=translate(IVideoParagraph[attr].title)))
   104         return output
   110         return output
       
   111 
       
   112 
       
   113 @vocabulary_config(name=VIDEO_PARAGRAPH_RENDERERS)
       
   114 class VideoParagraphRendererVocabulary(SimpleVocabulary):
       
   115     """Video paragraph renderers vocabulary"""
       
   116 
       
   117     def __init__(self, context=None):
       
   118         request = check_request()
       
   119         translate = request.localizer.translate
       
   120         registry = request.registry
       
   121         if not IVideoParagraph.providedBy(context):
       
   122             context = VideoParagraph()
       
   123         terms = [SimpleTerm(name, title=translate(adapter.label))
       
   124                  for name, adapter in sorted(registry.getAdapters((context, request), IContentRenderer),
       
   125                                              key=lambda x: x[1].weight)]
       
   126         super(VideoParagraphRendererVocabulary, self).__init__(terms)