Added form 'preview' and 'review' features support, and added form content checker
authorThierry Florac <thierry.florac@onf.fr>
Fri, 10 Nov 2017 11:59:46 +0100
changeset 263 f4d7aa39fd50
parent 262 851146db44da
child 264 1ee1a79dd347
Added form 'preview' and 'review' features support, and added form content checker
src/pyams_content/shared/form/__init__.py
--- a/src/pyams_content/shared/form/__init__.py	Fri Nov 10 11:59:05 2017 +0100
+++ b/src/pyams_content/shared/form/__init__.py	Fri Nov 10 11:59:46 2017 +0100
@@ -16,17 +16,24 @@
 # import standard library
 
 # import interfaces
+from pyams_content.features.checker.interfaces import IContentChecker, ERROR_VALUE
+from pyams_content.features.preview.interfaces import IPreviewTarget
+from pyams_content.features.review.interfaces import IReviewTarget
 from pyams_content.shared.form.interfaces import IWfForm, IForm, FORM_CONTENT_TYPE, FORM_CONTENT_NAME, \
-    IFormFieldContainerTarget, IFormHandler
+    IFormFieldContainerTarget, IFormHandler, IFormFieldContainer
 
 # import packages
-from pyams_content.shared.common import WfSharedContent, register_content_type, SharedContent
+from pyams_content.shared.common import WfSharedContent, SharedContent, register_content_type, WfSharedContentChecker
+from pyams_utils.adapter import adapter_config
 from zope.component.globalregistry import getGlobalSiteManager
 from zope.interface import implementer, alsoProvides, noLongerProvides
 from zope.schema.fieldproperty import FieldProperty
 
+from pyams_content import _
 
-@implementer(IWfForm, IFormFieldContainerTarget)
+
+@implementer(IWfForm, IFormFieldContainerTarget,
+             IPreviewTarget, IReviewTarget)
 class WfForm(WfSharedContent):
     """Base form"""
 
@@ -74,3 +81,16 @@
     """Workflow managed form class"""
 
     content_class = WfForm
+
+
+@adapter_config(name='properties', context=IWfForm, provides=IContentChecker)
+class WfFormContentChecker(WfSharedContentChecker):
+    """Form content checker"""
+
+    def inner_check(self, request):
+        output = super(WfFormContentChecker, self).inner_check(request)
+        translate = request.localizer.translate
+        if not IFormFieldContainer(self.context).get_fields():
+            output.append(translate(ERROR_VALUE).format(field=translate(_("Form fields")),
+                                                        message=translate(_("no field defined"))))
+        return output