src/pyams_content/component/paragraph/video.py
changeset 241 50452584f7ae
parent 192 8a16d2f507d7
child 355 5dce53509832
--- a/src/pyams_content/component/paragraph/video.py	Fri Nov 10 11:47:23 2017 +0100
+++ b/src/pyams_content/component/paragraph/video.py	Fri Nov 10 11:47:59 2017 +0100
@@ -9,10 +9,6 @@
 # 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'
 
@@ -24,11 +20,18 @@
 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
+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
 
 # import packages
-from pyams_content.component.paragraph import BaseParagraph
+from pyams_content.component.paragraph import BaseParagraph, BaseParagraphContentChecker
+from pyams_content.component.paragraph.html import check_associations
 from pyams_file.property import FileProperty
-from pyams_utils.registry import utility_config
+from pyams_utils.adapter import adapter_config
+from pyams_utils.registry import utility_config, get_utility
+from pyams_utils.traversing import get_parent
+from pyramid.events import subscriber
 from zope.interface import implementer
 from zope.schema.fieldproperty import FieldProperty
 
@@ -70,3 +73,32 @@
     paragraph = event.object
     for lang, body in (paragraph.body or {}).items():
         check_associations(paragraph, body, lang, notify=False)
+
+
+@adapter_config(context=IVideoParagraph, provides=IContentChecker)
+class VideoParagraphContentChecker(BaseParagraphContentChecker):
+    """Video paragraph content checker"""
+
+    def inner_check(self, request):
+        output = []
+        translate = request.localizer.translate
+        manager = get_parent(self.context, II18nManager)
+        if manager is not None:
+            langs = manager.get_languages()
+        else:
+            negotiator = get_utility(INegotiator)
+            langs = (negotiator.server_language, )
+        i18n = II18n(self.context)
+        for lang in langs:
+            value = i18n.get_attribute('title', lang, request)
+            if not value:
+                field_title = translate(IVideoParagraph['title'].title)
+                if len(langs) == 1:
+                    output.append(translate(MISSING_VALUE).format(field=field_title))
+                else:
+                    output.append(translate(MISSING_LANG_VALUE).format(field=field_title, lang=lang))
+        for attr in ('author', 'data'):
+            value = getattr(self.context, attr)
+            if not value:
+                output.append(translate(MISSING_VALUE).format(field=translate(IVideoParagraph[attr].title)))
+        return output