Updated contributor checks on publication request
authorThierry Florac <thierry.florac@onf.fr>
Tue, 17 Jul 2018 15:01:28 +0200
changeset 851 7a555a68a9f2
parent 850 0a2997609f75
child 852 ae0c84d7029f
Updated contributor checks on publication request
src/pyams_content/shared/common/zmi/workflow.py
--- a/src/pyams_content/shared/common/zmi/workflow.py	Tue Jul 17 12:25:41 2018 +0200
+++ b/src/pyams_content/shared/common/zmi/workflow.py	Tue Jul 17 15:01:28 2018 +0200
@@ -9,6 +9,7 @@
 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
 # FOR A PARTICULAR PURPOSE.
 #
+from pyams_content.features.preview.interfaces import IPreviewTarget
 
 __docformat__ = 'restructuredtext'
 
@@ -847,15 +848,25 @@
     label_css_class = 'control-label col-md-4'
     input_css_class = 'col-md-8'
 
-    fields = field.Fields(IContributorChecks)
-    fields['preview'].widgetFactory = PreviewFieldWidget
-    fields['check'].widgetFactory = CheckFieldWidget
+    @property
+    def fields(self):
+        fields = field.Fields(IContributorChecks)
+        if not IPreviewTarget.providedBy(self.context):
+            fields = fields.omit('preview')
+        else:
+            fields['preview'].widgetFactory = PreviewFieldWidget
+        fields['check'].widgetFactory = CheckFieldWidget
+        return fields
 
 
 @subscriber(IDataExtractedEvent, form_selector=ContributorChecksForm)
 def handle_contributor_checks_data_extraction(event):
     """Handle extraction of contributor checks"""
     data = event.data
-    if not (data.get('preview') and data.get('check')):
-        event.form.widgets.errors += (Invalid(_("You must confirm that you previewed and checked this content before " 
-                                                "requesting publication!!")), )
+    can_preview = IPreviewTarget.providedBy(event.form.context)
+    if can_preview and (not (data.get('preview') and data.get('check'))):
+        event.form.widgets.errors += (Invalid(_("You must confirm that you previewed and checked this content before "
+                                                "requesting publication!!")),)
+    elif (not can_preview) and not data.get('check'):
+        event.form.widgets.errors += (Invalid(_("You must confirm that you checked this content before "
+                                                "requesting publication!!")),)