src/pyams_content/shared/logo/__init__.py
changeset 392 8fc847d83992
child 492 04503227569d
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/pyams_content/shared/logo/__init__.py	Fri Feb 09 17:48:34 2018 +0100
@@ -0,0 +1,67 @@
+#
+# 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.
+#
+
+__docformat__ = 'restructuredtext'
+
+
+# import standard library
+
+# import interfaces
+from pyams_content.features.checker.interfaces import IContentChecker, MISSING_VALUE
+from pyams_content.shared.logo.interfaces import IWfLogo, LOGO_CONTENT_TYPE, LOGO_CONTENT_NAME, ILogo
+from pyams_content.features.review import IReviewTarget
+
+# import packages
+from pyams_content.shared.common import WfSharedContent, register_content_type, SharedContent, WfSharedContentChecker
+from pyams_file.property import FileProperty
+from pyams_utils.adapter import adapter_config
+from zope.interface import implementer
+from zope.schema.fieldproperty import FieldProperty
+
+from pyams_content import _
+
+
+@implementer(IWfLogo, IReviewTarget)
+class WfLogo(WfSharedContent):
+    """Logo persistent class"""
+
+    content_type = LOGO_CONTENT_TYPE
+    content_name = LOGO_CONTENT_NAME
+
+    image = FileProperty(IWfLogo['image'])
+    url = FieldProperty(IWfLogo['url'])
+
+
+register_content_type(WfLogo)
+
+
+@implementer(ILogo)
+class Logo(SharedContent):
+    """WOrkflow managed logo persistent class"""
+
+    content_class = WfLogo
+
+
+@adapter_config(name='properties', context=IWfLogo, provides=IContentChecker)
+class WfLogoContentChecker(WfSharedContentChecker):
+    """Logo content checker"""
+
+    def inner_check(self, request):
+        output = super(WfLogoContentChecker, self).inner_check(request)
+        translate = request.localizer.translate
+        if not (self.context.image and self.context.image.get_size()):
+            output.append(translate(MISSING_VALUE).format(field=translate(IWfLogo['image'].title),
+                                                          message=translate(_("no image defined"))))
+        if not self.context.url:
+            output.append(translate(MISSING_VALUE).format(field=translate(IWfLogo['url'].title),
+                                                          message=translate(_("no URL defined"))))
+        return output