Added themes content checker
authorThierry Florac <thierry.florac@onf.fr>
Fri, 10 Nov 2017 11:47:23 +0100
changeset 240 0eca05146080
parent 239 b3b7d4bf63f7
child 241 50452584f7ae
Added themes content checker
src/pyams_content/component/theme/__init__.py
--- a/src/pyams_content/component/theme/__init__.py	Fri Nov 10 11:46:51 2017 +0100
+++ b/src/pyams_content/component/theme/__init__.py	Fri Nov 10 11:47:23 2017 +0100
@@ -16,12 +16,14 @@
 # import standard library
 
 # import interfaces
-from pyams_content.component.theme.interfaces import IThemesManagerTarget, IThemesManager, THEMES_MANAGER_KEY, IThemesInfo, \
-    IThemesTarget, THEMES_INFO_KEY
+from pyams_content.component.theme.interfaces import IThemesManagerTarget, IThemesManager, THEMES_MANAGER_KEY, \
+    IThemesTarget, IThemesInfo, THEMES_INFO_KEY
+from pyams_content.features.checker.interfaces import IContentChecker, ERROR_VALUE
 from zope.annotation.interfaces import IAnnotations
 
 # import packages
 from persistent import Persistent
+from pyams_content.features.checker import BaseContentChecker
 from pyams_utils.adapter import adapter_config
 from pyramid.threadlocal import get_current_registry
 from zope.container.contained import Contained
@@ -30,6 +32,8 @@
 from zope.location import locate
 from zope.schema.fieldproperty import FieldProperty
 
+from pyams_content import _
+
 
 @implementer(IThemesManager)
 class ThemesManager(Persistent, Contained):
@@ -68,3 +72,20 @@
         get_current_registry().notify(ObjectCreatedEvent(info))
         locate(info, target, '++themes++')
     return info
+
+
+@adapter_config(name='themes', context=IThemesTarget, provides=IContentChecker)
+class ThemesContentChecker(BaseContentChecker):
+    """Themes info content checker"""
+
+    label = _("Themes")
+    weight = 200
+
+    def inner_check(self, request):
+        output = []
+        translate = request.localizer.translate
+        themes = IThemesInfo(self.context)
+        if not themes.themes:
+            output.append(translate(ERROR_VALUE).format(field=translate(IThemesInfo['themes'].title),
+                                                        message=translate(_("no defined theme"))))
+        return output