--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/pyams_content/component/paragraph/video.py Thu Sep 21 14:31:04 2017 +0200
@@ -0,0 +1,72 @@
+#
+# Copyright (c) 2008-2015 Thierry Florac <tflorac AT ulthar.net>
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+from pyramid.events import subscriber
+from zope.lifecycleevent.interfaces import IObjectAddedEvent, IObjectModifiedEvent
+
+from pyams_content.component.paragraph.html import check_associations
+
+__docformat__ = 'restructuredtext'
+
+
+# import standard library
+
+# import interfaces
+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
+
+# import packages
+from pyams_content.component.paragraph import BaseParagraph
+from pyams_file.property import FileProperty
+from pyams_utils.registry import utility_config
+from zope.interface import implementer
+from zope.schema.fieldproperty import FieldProperty
+
+from pyams_content import _
+
+
+@implementer(IVideoParagraph, IExtFileContainerTarget, ILinkContainerTarget)
+class VideoParagraph(BaseParagraph):
+ """Video paragraph class"""
+
+ icon_class = 'fa-film'
+ icon_hint = _("Video")
+
+ body = FieldProperty(IVideoParagraph['body'])
+ description = FieldProperty(IVideoParagraph['description'])
+ author = FieldProperty(IVideoParagraph['author'])
+ data = FileProperty(IVideoParagraph['data'])
+
+
+@utility_config(name='video', provides=IParagraphFactory)
+class VideoParagraphFactory(object):
+ """Video paragraph factory"""
+
+ name = _("Video")
+ content_type = VideoParagraph
+
+
+@subscriber(IObjectAddedEvent, context_selector=IVideoParagraph)
+def handle_added_video_paragraph(event):
+ """Check for new associations from added paragraph"""
+ paragraph = event.object
+ for lang, body in (paragraph.body or {}).items():
+ check_associations(paragraph, body, lang, notify=False)
+
+
+@subscriber(IObjectModifiedEvent, context_selector=IVideoParagraph)
+def handle_modified_video_paragraph(event):
+ """Check for new associations from modified paragraph"""
+ paragraph = event.object
+ for lang, body in (paragraph.body or {}).items():
+ check_associations(paragraph, body, lang, notify=False)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/pyams_content/component/paragraph/zmi/video.py Thu Sep 21 14:31:04 2017 +0200
@@ -0,0 +1,231 @@
+#
+# Copyright (c) 2008-2015 Thierry Florac <tflorac AT ulthar.net>
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+from pyramid.view import view_config
+from transaction.interfaces import ITransactionManager
+
+from pyams_content.component.association.zmi import AssociationsTable
+from pyams_content.component.association.zmi.interfaces import IAssociationsParentForm
+from pyams_content.component.paragraph.interfaces import IParagraphContainerTarget, IParagraphContainer, \
+ IParagraphSummary
+from pyams_content.component.paragraph.interfaces.video import IVideoParagraph
+from pyams_content.component.paragraph.video import VideoParagraph
+from pyams_content.component.paragraph.zmi import BaseParagraphAJAXAddForm, BaseParagraphAJAXEditForm
+from pyams_content.component.paragraph.zmi.container import ParagraphContainerView
+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
+from pyams_form.group import NamedWidgetsGroup
+from pyams_form.interfaces.form import IInnerForm, IEditFormButtons
+from pyams_form.security import ProtectedFormObjectMixin
+from pyams_i18n.interfaces import II18n
+from pyams_pagelet.pagelet import pagelet_config
+from pyams_skin.interfaces.viewlet import IToolbarAddingMenu
+from pyams_skin.layer import IPyAMSLayer
+from pyams_skin.viewlet.toolbar import ToolbarMenuItem
+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, BaseContentProvider
+from pyams_zmi.form import AdminDialogAddForm, AdminDialogEditForm
+from pyams_zmi.interfaces import IPropertiesEditForm
+
+__docformat__ = 'restructuredtext'
+
+
+# import standard library
+
+# import interfaces
+from z3c.form.interfaces import INPUT_MODE
+
+# import packages
+from z3c.form import field, button
+from zope.interface import implementer
+
+from pyams_content import _
+
+
+@viewlet_config(name='add-video-paragraph.menu', context=IParagraphContainerTarget, view=ParagraphContainerView,
+ layer=IPyAMSLayer, manager=IToolbarAddingMenu, weight=70)
+class VideoParagraphAddMenu(ProtectedFormObjectMixin, ToolbarMenuItem):
+ """Video paragraph add menu"""
+
+ label = _("Add video paragraph...")
+ label_css_class = 'fa fa-fw fa-film'
+ url = 'add-video-paragraph.html'
+ modal_target = True
+
+
+@pagelet_config(name='add-video-paragraph.html', context=IParagraphContainerTarget, layer=IPyAMSLayer,
+ permission=MANAGE_CONTENT_PERMISSION)
+class VideoParagraphAddForm(AdminDialogAddForm):
+ """Video paragraph add form"""
+
+ legend = _("Add new video paragraph")
+ dialog_class = 'modal-large'
+ icon_css_class = 'fa fa-fw fa-film'
+
+ fields = field.Fields(IVideoParagraph).omit('__parent__', '__name__', 'visible')
+ ajax_handler = 'add-video-paragraph.json'
+ edit_permission = MANAGE_CONTENT_PERMISSION
+
+ def updateWidgets(self, prefix=None):
+ super(VideoParagraphAddForm, self).updateWidgets(prefix)
+ if 'description' in self.widgets:
+ self.widgets['description'].widget_css_class = 'textarea'
+ if 'body' in self.widgets:
+ self.widgets['body'].label = ''
+ self.add_group(NamedWidgetsGroup(self, 'body_group', self.widgets, ('body',),
+ bordered=False,
+ legend=_("HTML content"),
+ css_class='inner switcher padding-right-10 no-y-padding pull-left',
+ switch=True,
+ hide_if_empty=True))
+ self.add_group(NamedWidgetsGroup(self, 'data_group', self.widgets,
+ ('description', 'author', 'data'),
+ bordered=False))
+
+ def create(self, data):
+ return VideoParagraph()
+
+ def add(self, object):
+ IParagraphContainer(self.context).append(object)
+
+
+@view_config(name='add-video-paragraph.json', context=IParagraphContainerTarget, request_type=IPyAMSLayer,
+ permission=MANAGE_CONTENT_PERMISSION, renderer='json', xhr=True)
+class VideoParagraphAJAXAddForm(BaseParagraphAJAXAddForm, VideoParagraphAddForm):
+ """Video paragraph add form, JSON renderer"""
+
+
+@pagelet_config(name='properties.html', context=IVideoParagraph, layer=IPyAMSLayer,
+ permission=MANAGE_CONTENT_PERMISSION)
+class VideoParagraphPropertiesEditForm(AdminDialogEditForm):
+ """Video paragraph properties edit form"""
+
+ @property
+ def title(self):
+ content = get_parent(self.context, IWfSharedContent)
+ return II18n(content).query_attribute('title', request=self.request)
+
+ legend = _("Edit video properties")
+ dialog_class = 'modal-large'
+ icon_css_class = 'fa fa-fw fa-film'
+
+ fields = field.Fields(IVideoParagraph).omit('__parent__', '__name__', 'visible')
+ ajax_handler = 'properties.json'
+ edit_permission = MANAGE_CONTENT_PERMISSION
+
+ def updateWidgets(self, prefix=None):
+ super(VideoParagraphPropertiesEditForm, self).updateWidgets(prefix)
+ if 'description' in self.widgets:
+ self.widgets['description'].widget_css_class = 'textarea'
+ if 'body' in self.widgets:
+ self.widgets['body'].label = ''
+ self.add_group(NamedWidgetsGroup(self, 'body_group', self.widgets, ('body',),
+ bordered=False,
+ fieldset_class='margin-top-10 padding-y-5',
+ legend=_("HTML content"),
+ css_class='inner switcher padding-right-10 no-y-padding pull-left',
+ switch=True,
+ hide_if_empty=True))
+ self.add_group(NamedWidgetsGroup(self, 'data_group', self.widgets,
+ ('description', 'author', 'data'),
+ bordered=False))
+
+
+@view_config(name='properties.json', context=IVideoParagraph, request_type=IPyAMSLayer,
+ permission=MANAGE_CONTENT_PERMISSION, renderer='json', xhr=True)
+class VideoParagraphPropertiesAJAXEditForm(BaseParagraphAJAXEditForm, VideoParagraphPropertiesEditForm):
+ """Video paragraph properties edit form, JSON renderer"""
+
+ def get_ajax_output(self, changes):
+ output = super(VideoParagraphPropertiesAJAXEditForm, self).get_ajax_output(changes)
+ if 'body' in changes.get(IVideoParagraph, ()):
+ associations_table = AssociationsTable(self.context, self.request)
+ associations_table.update()
+ output.setdefault('events', []).append({
+ 'event': 'PyAMS_content.changed_item',
+ 'options': {'object_type': 'associations',
+ 'object_name': associations_table.id,
+ 'table': associations_table.render()}})
+ return output
+
+
+@adapter_config(context=(IVideoParagraph, IPyAMSLayer), provides=IParagraphInnerEditor)
+@implementer(IInnerForm, IPropertiesEditForm, IAssociationsParentForm)
+class VideoParagraphPropertiesInnerEditForm(VideoParagraphPropertiesEditForm):
+ """Video paragraph properties inner edit form"""
+
+ legend = None
+ ajax_handler = 'inner-properties.json'
+
+ @property
+ def buttons(self):
+ if self.mode == INPUT_MODE:
+ return button.Buttons(IEditFormButtons)
+ else:
+ return button.Buttons()
+
+
+@view_config(name='inner-properties.json', context=IVideoParagraph, request_type=IPyAMSLayer,
+ permission=MANAGE_CONTENT_PERMISSION, renderer='json', xhr=True)
+class VideoParagraphPropertiesInnerAJAXEditForm(BaseParagraphAJAXEditForm, VideoParagraphPropertiesInnerEditForm):
+ """Video paragraph properties inner deit form, JSON renderer"""
+
+ def get_ajax_output(self, changes):
+ output = super(VideoParagraphPropertiesInnerAJAXEditForm, self).get_ajax_output(changes)
+ updated = changes.get(IVideoParagraph, ())
+ if 'body' in updated:
+ associations_table = AssociationsTable(self.context, self.request)
+ associations_table.update()
+ output.setdefault('events', []).append({
+ 'event': 'PyAMS_content.changed_item',
+ 'options': {'object_type': 'associations',
+ 'object_name': associations_table.id,
+ 'table': associations_table.render()}
+ })
+ if 'data' in updated:
+ # we have to commit transaction to be able to handle blobs...
+ ITransactionManager(self.context).get().commit()
+ form = VideoParagraphPropertiesInnerEditForm(self.context, self.request)
+ form.update()
+ output.setdefault('events', []).append({
+ 'event': 'PyAMS_content.changed_item',
+ 'options': {'object_type': 'form',
+ 'object_name': '{0}_{1}_{2}'.format(
+ self.context.__class__.__name__,
+ getattr(form.getContent(), '__name__', 'noname').replace('++', ''),
+ form.id),
+ 'form': form.render()}
+ })
+ return output
+
+
+#
+# Video summary
+#
+
+@adapter_config(context=(IVideoParagraph, IPyAMSLayer), provides=IParagraphSummary)
+@template_config(template='templates/video-summary.pt', layer=IPyAMSLayer)
+class VideoParagraphSummary(BaseContentProvider):
+ """Video paragraph summary"""
+
+ language = None
+
+ def update(self):
+ i18n = II18n(self.context)
+ if self.language:
+ for attr in ('title', 'body', 'description'):
+ setattr(self, attr, i18n.get_attribute(attr, self.language, request=self.request))
+ else:
+ for attr in ('title', 'body', 'description'):
+ setattr(self, attr, i18n.query_attribute(attr, request=self.request))