src/pyams_content/component/paragraph/video.py
changeset 181 6d75755407b7
child 192 8a16d2f507d7
--- /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)