--- a/src/pyams_content/component/video/interfaces/__init__.py Wed Apr 25 17:32:29 2018 +0200
+++ b/src/pyams_content/component/video/interfaces/__init__.py Thu Apr 26 17:03:59 2018 +0200
@@ -37,6 +37,8 @@
class IExternalVideoProvider(Interface):
"""External video provider"""
+ label = Attribute("Video provider label")
+ weight = Attribute("Video provider weight (used for ordering)")
settings_interface = Attribute("Video provider settings interface")
--- a/src/pyams_content/component/video/provider/__init__.py Wed Apr 25 17:32:29 2018 +0200
+++ b/src/pyams_content/component/video/provider/__init__.py Thu Apr 26 17:03:59 2018 +0200
@@ -9,6 +9,10 @@
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
+from zope.component._api import getUtilitiesFor
+from zope.schema.vocabulary import SimpleVocabulary, SimpleTerm
+
+from pyams_utils.request import check_request
__docformat__ = 'restructuredtext'
@@ -16,16 +20,78 @@
# import standard library
# import interfaces
-from pyams_content.component.video.interfaces import IExternalVideoProvider
+from pyams_content.component.video.interfaces import IExternalVideo, IExternalVideoProvider, IExternalVideoSettings
+from pyams_content.component.video.provider.interfaces import ICustomVideoSettings
+from pyams_content.features.checker.interfaces import IContentChecker
# import packages
+from persistent import Persistent
+from pyams_content.component.video import external_video_settings_factory
+from pyams_content.features.checker import BaseContentChecker
+from pyams_utils.adapter import adapter_config
+from pyams_utils.registry import utility_config
from pyams_utils.vocabulary import vocabulary_config
-from zope.componentvocabulary.vocabulary import UtilityVocabulary
+from zope.interface import implementer
+from zope.schema.fieldproperty import FieldProperty
+
+from pyams_content import _
@vocabulary_config(name='PyAMS video providers')
-class VideoProvidersVocabulary(UtilityVocabulary):
+class VideoProvidersVocabulary(SimpleVocabulary):
"""Video providers vocabulary"""
interface = IExternalVideoProvider
- nameOnly = True
+
+ def __init__(self, context):
+ request = check_request()
+ translate = request.localizer.translate
+ utils = sorted(getUtilitiesFor(self.interface, context),
+ key=lambda x: getattr(x[1], 'weight', 0))
+ terms = [SimpleTerm(name, title=translate(getattr(util, 'label', name))) for name, util in utils]
+ super(VideoProvidersVocabulary, self).__init__(terms)
+
+
+#
+# Custom video provider settings
+#
+
+@implementer(ICustomVideoSettings)
+class CustomVideoSettings(Persistent):
+ """Custom video provider settings"""
+
+ integration_code = FieldProperty(ICustomVideoSettings['integration_code'])
+
+
+@utility_config(name='custom', provides=IExternalVideoProvider)
+class CustomVideoProvider(object):
+ """Custom video provider"""
+
+ label = _("Other provider")
+ weight = 99
+
+ settings_interface = ICustomVideoSettings
+
+
+@adapter_config(context=IExternalVideo, provides=ICustomVideoSettings)
+def custom_video_settings_factory(context):
+ """Customp video settings factory"""
+ if context.provider_name != 'custom':
+ return None
+ return external_video_settings_factory(context)
+
+
+@adapter_config(context=CustomVideoProvider, provides=IExternalVideoSettings)
+def custom_video_provider_settings_factory(context):
+ """Custom video provider settings factory"""
+ return CustomVideoSettings()
+
+
+@adapter_config(context=ICustomVideoSettings, provides=IContentChecker)
+class CustomVideoSettingsContentChecker(BaseContentChecker):
+ """Custom video settings content checker"""
+
+ label = _("Custom video settings")
+
+ def inner_check(self, request):
+ return []
--- a/src/pyams_content/component/video/provider/dailymotion.py Wed Apr 25 17:32:29 2018 +0200
+++ b/src/pyams_content/component/video/provider/dailymotion.py Thu Apr 26 17:03:59 2018 +0200
@@ -41,8 +41,6 @@
"""Dailymotion video settings"""
_video_id = FieldProperty(IDailymotionVideoSettings['video_id'])
- width = FieldProperty(IDailymotionVideoSettings['width'])
- height = FieldProperty(IDailymotionVideoSettings['height'])
start_at = FieldProperty(IDailymotionVideoSettings['start_at'])
autoplay = FieldProperty(IDailymotionVideoSettings['autoplay'])
show_info = FieldProperty(IDailymotionVideoSettings['show_info'])
@@ -52,6 +50,8 @@
show_endscreen = FieldProperty(IDailymotionVideoSettings['show_endscreen'])
allow_fullscreen = FieldProperty(IDailymotionVideoSettings['allow_fullscreen'])
allow_sharing = FieldProperty(IDailymotionVideoSettings['allow_sharing'])
+ width = FieldProperty(IDailymotionVideoSettings['width'])
+ height = FieldProperty(IDailymotionVideoSettings['height'])
@property
def video_id(self):
--- a/src/pyams_content/component/video/provider/interfaces.py Wed Apr 25 17:32:29 2018 +0200
+++ b/src/pyams_content/component/video/provider/interfaces.py Thu Apr 26 17:03:59 2018 +0200
@@ -20,11 +20,20 @@
# import packages
from pyams_utils.schema import ColorField
-from zope.schema import TextLine, Bool, Int, Choice
+from zope.schema import Text, TextLine, Bool, Int, Choice
from pyams_content import _
+class ICustomVideoSettings(IExternalVideoSettings):
+ """Custom external video provider settings"""
+
+ integration_code = Text(title=_("Integration code"),
+ description=_("Please select integration code provided by your video provider, "
+ "and paste it here"),
+ required=True)
+
+
class IYoutubeVideoSettings(IExternalVideoSettings):
"""Youtube video provider settings"""
@@ -33,20 +42,6 @@
"copy/paste the given URL here"),
required=True)
- width = Int(title=_("Video width"),
- description=_("Initial video frame width; mandatory for old browsers but may be overridden by "
- "presentation skin"),
- required=True,
- min=200,
- default=720)
-
- height = Int(title=_("Video height"),
- description=_("Initial video frame height; mandatory for old browsers but may be overridden by "
- "presentation skin"),
- required=True,
- min=200,
- default=405)
-
start_at = TextLine(title=_("Start at"),
description=_("Position at which to start video, in 'seconds' or 'minutes:seconds' format"),
required=False,
@@ -77,14 +72,14 @@
default=True)
hide_branding = Bool(title=_("Hide branding?"),
- description=_("If 'yes', Youtube branding won't be displayed"),
+ description=_("If 'no', Youtube branding will be displayed"),
required=True,
- default=False)
+ default=True)
show_related = Bool(title=_("Show related videos?"),
description=_("Show related videos when video end"),
required=True,
- default=True)
+ default=False)
allow_fullscreen = Bool(title=_("Allow full screen?"),
description=_("If 'yes', video can be displayed in full screen"),
@@ -96,15 +91,6 @@
required=True,
default=False)
-
-class IDailymotionVideoSettings(IExternalVideoSettings):
- """Dailymotion video provider settings"""
-
- video_id = TextLine(title=_("Video ID"),
- description=_("To get video ID, just use the 'Share' button in Dailymotion platform, "
- "click on \"Copy link\" and paste the given URL here"),
- required=True)
-
width = Int(title=_("Video width"),
description=_("Initial video frame width; mandatory for old browsers but may be overridden by "
"presentation skin"),
@@ -119,6 +105,15 @@
min=200,
default=405)
+
+class IDailymotionVideoSettings(IExternalVideoSettings):
+ """Dailymotion video provider settings"""
+
+ video_id = TextLine(title=_("Video ID"),
+ description=_("To get video ID, just use the 'Share' button in Dailymotion platform, "
+ "click on \"Copy link\" and paste the given URL here"),
+ required=True)
+
start_at = TextLine(title=_("Start at"),
description=_("Position at which to start video, in 'seconds' or 'minutes:seconds' format"),
required=False,
@@ -145,14 +140,14 @@
default='dark')
show_branding = Bool(title=_("Show branding?"),
- description=_("If 'no', Dailymotion branding won't be displayed"),
+ description=_("If 'yes', Dailymotion branding will be displayed"),
required=True,
- default=True)
+ default=False)
show_endscreen = Bool(title=_("Show end screen?"),
description=_("Show end screen when video end"),
required=True,
- default=True)
+ default=False)
allow_fullscreen = Bool(title=_("Allow full screen?"),
description=_("If 'yes', video can be displayed in full screen"),
@@ -164,15 +159,6 @@
required=True,
default=True)
-
-class IVimeoVideoSettings(IExternalVideoSettings):
- """Vimeo video provider settings"""
-
- video_id = TextLine(title=_("Video ID"),
- description=_("To get video ID, just use the 'Share' button in Vimeo platform, "
- "click on \"Link\" entry and copy/paste the given URL here"),
- required=True)
-
width = Int(title=_("Video width"),
description=_("Initial video frame width; mandatory for old browsers but may be overridden by "
"presentation skin"),
@@ -187,13 +173,22 @@
min=200,
default=405)
+
+class IVimeoVideoSettings(IExternalVideoSettings):
+ """Vimeo video provider settings"""
+
+ video_id = TextLine(title=_("Video ID"),
+ description=_("To get video ID, just use the 'Share' button in Vimeo platform, "
+ "click on \"Link\" entry and copy/paste the given URL here"),
+ required=True)
+
show_title = Bool(title=_("Show title?"),
description=_("If 'no', video title won't be displayed"),
required=True,
default=True)
show_signature = Bool(title=_("Show signature?"),
- description=_("If 'no', video signature won't be displayed"),
+ description=_("If 'no', video's author signature won't be displayed"),
required=True,
default=True)
@@ -216,3 +211,17 @@
description=_("If 'yes', video can be displayed in full screen"),
required=True,
default=True)
+
+ width = Int(title=_("Video width"),
+ description=_("Initial video frame width; mandatory for old browsers but may be overridden by "
+ "presentation skin"),
+ required=True,
+ min=200,
+ default=720)
+
+ height = Int(title=_("Video height"),
+ description=_("Initial video frame height; mandatory for old browsers but may be overridden by "
+ "presentation skin"),
+ required=True,
+ min=200,
+ default=405)
--- a/src/pyams_content/component/video/provider/vimeo.py Wed Apr 25 17:32:29 2018 +0200
+++ b/src/pyams_content/component/video/provider/vimeo.py Thu Apr 26 17:03:59 2018 +0200
@@ -42,14 +42,14 @@
"""Vimeo video settings"""
_video_id = FieldProperty(IVimeoVideoSettings['video_id'])
- width = FieldProperty(IVimeoVideoSettings['width'])
- height = FieldProperty(IVimeoVideoSettings['height'])
show_title = FieldProperty(IVimeoVideoSettings['show_title'])
show_signature = FieldProperty(IVimeoVideoSettings['show_signature'])
color = FieldProperty(IVimeoVideoSettings['color'])
autoplay = FieldProperty(IVimeoVideoSettings['autoplay'])
loop = FieldProperty(IVimeoVideoSettings['loop'])
allow_fullscreen = FieldProperty(IVimeoVideoSettings['allow_fullscreen'])
+ width = FieldProperty(IVimeoVideoSettings['width'])
+ height = FieldProperty(IVimeoVideoSettings['height'])
@property
def video_id(self):
--- a/src/pyams_content/component/video/provider/youtube.py Wed Apr 25 17:32:29 2018 +0200
+++ b/src/pyams_content/component/video/provider/youtube.py Thu Apr 26 17:03:59 2018 +0200
@@ -42,8 +42,6 @@
"""Youtube video settings"""
_video_id = FieldProperty(IYoutubeVideoSettings['video_id'])
- width = FieldProperty(IYoutubeVideoSettings['width'])
- height = FieldProperty(IYoutubeVideoSettings['height'])
start_at = FieldProperty(IYoutubeVideoSettings['start_at'])
stop_at = FieldProperty(IYoutubeVideoSettings['stop_at'])
autoplay = FieldProperty(IYoutubeVideoSettings['autoplay'])
@@ -54,6 +52,8 @@
show_related = FieldProperty(IYoutubeVideoSettings['show_related'])
allow_fullscreen = FieldProperty(IYoutubeVideoSettings['allow_fullscreen'])
disable_keyboard = FieldProperty(IYoutubeVideoSettings['disable_keyboard'])
+ width = FieldProperty(IYoutubeVideoSettings['width'])
+ height = FieldProperty(IYoutubeVideoSettings['height'])
@property
def video_id(self):
--- a/src/pyams_content/component/video/provider/zmi/__init__.py Wed Apr 25 17:32:29 2018 +0200
+++ b/src/pyams_content/component/video/provider/zmi/__init__.py Thu Apr 26 17:03:59 2018 +0200
@@ -9,6 +9,7 @@
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
+from pyams_content.component.video.provider import CustomVideoSettings
__docformat__ = 'restructuredtext'
@@ -86,6 +87,12 @@
return urlencode(params)
+@adapter_config(context=(CustomVideoSettings, IPyAMSLayer), provides=IExternalVideoRenderer)
+@template_config(template='templates/custom-render.pt', layer=IPyAMSLayer)
+class CustomVideoRenderer(BaseExternalVideoRenderer):
+ """Custom video renderer"""
+
+
@adapter_config(context=(YoutubeVideoSettings, IPyAMSLayer), provides=IExternalVideoRenderer)
@template_config(template='templates/youtube-render.pt', layer=IPyAMSLayer)
class YoutubeVideoRenderer(BaseExternalVideoRenderer):
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/pyams_content/component/video/provider/zmi/templates/custom-render.pt Thu Apr 26 17:03:59 2018 +0200
@@ -0,0 +1,3 @@
+<div class="video-wrapper">
+ <tal:var replace="structure context.integration_code">Integration code</tal:var>
+</div>
--- a/src/pyams_content/component/video/zmi/paragraph.py Wed Apr 25 17:32:29 2018 +0200
+++ b/src/pyams_content/component/video/zmi/paragraph.py Thu Apr 26 17:03:59 2018 +0200
@@ -113,6 +113,7 @@
if settings is not None:
provider = content.get_provider()
form = InnerAdminEditForm(settings, self.request)
+ form.prefix = self.prefix
form.edit_permission = MANAGE_CONTENT_PERMISSION
form.fields = field.Fields(provider.settings_interface)
form.update()
@@ -158,19 +159,27 @@
else:
provider = get_utility(IExternalVideoProvider, name=provider_name)
form = InnerAdminAddForm(request.context, request)
+ form.prefix = ExternalVideoParagraphAddForm.prefix
form.legend = request.localizer.translate(_("Video provider settings"))
form.label_css_class = 'control-label col-md-4'
form.input_css_class = 'col-md-8'
form.fields = field.Fields(provider.settings_interface)
form.update()
- form.add_group(NamedWidgetsGroup(form, 'video_id', form.widgets, ('video_id', ), bordered=False))
- form.add_group(NamedWidgetsGroup(form, 'provider_group', form.widgets,
- getFieldNamesInOrder(provider.settings_interface)[1:],
- bordered=False,
- legend=_("Other settings"),
- css_class="inner switcher padding-right-10 no-y-padding",
- switch=True,
- hide_if_empty=True))
+ if 'integration_code' in form.widgets: # custom video provider
+ form.widgets['integration_code'].widget_css_class = 'textarea'
+ form.add_group(NamedWidgetsGroup(form, 'integration_code', form.widgets, ('integration_code', ),
+ bordered=False))
+ elif 'video_id' in form.widgets:
+ form.add_group(NamedWidgetsGroup(form, 'video_id', form.widgets, ('video_id', ), bordered=False))
+ field_names = getFieldNamesInOrder(provider.settings_interface)
+ if len(field_names) > 1:
+ form.add_group(NamedWidgetsGroup(form, 'provider_group', form.widgets,
+ field_names[1:],
+ bordered=False,
+ legend=_("Other settings"),
+ css_class="inner switcher padding-right-10 no-y-padding",
+ switch=True,
+ hide_if_empty=True))
return Response(form.render())
@@ -215,15 +224,22 @@
self.widgets['provider_name'].mode = DISPLAY_MODE
provider = self.context.get_provider()
if provider is not None:
- self.add_group(NamedWidgetsGroup(self, 'video_id', self.widgets, ('video_id',), bordered=False))
- self.add_group(NamedWidgetsGroup(self, 'provider_group', self.widgets,
- getFieldNamesInOrder(provider.settings_interface)[1:],
- bordered=False,
- legend=_("Video provider settings"),
- fieldset_class='margin-top-10 padding-y-5',
- css_class='inner switcher padding-right-10 no-y-padding pull-left',
- switch=True,
- hide_if_empty=True))
+ if 'integration_code' in self.widgets: # custom video provider
+ self.widgets['integration_code'].widget_css_class = 'textarea'
+ self.add_group(NamedWidgetsGroup(self, 'integration_code', self.widgets, ('integration_code',),
+ bordered=False))
+ elif 'video_id' in self.widgets:
+ self.add_group(NamedWidgetsGroup(self, 'video_id', self.widgets, ('video_id',), bordered=False))
+ field_names = getFieldNamesInOrder(provider.settings_interface)
+ if len(field_names) > 1:
+ self.add_group(NamedWidgetsGroup(self, 'provider_group', self.widgets,
+ field_names[1:],
+ bordered=False,
+ legend=_("Video provider settings"),
+ fieldset_class='margin-top-10 padding-y-5',
+ css_class='inner switcher padding-right-10 no-y-padding pull-left',
+ switch=True,
+ hide_if_empty=True))
@view_config(name='properties.json', context=IExternalVideoParagraph, request_type=IPyAMSLayer,