# HG changeset patch # User Thierry Florac # Date 1531832488 -7200 # Node ID 7a555a68a9f2e980f1e286b07d7aac69bfdfb611 # Parent 0a2997609f75a08d9f4378df43aad5a2a9393c2a Updated contributor checks on publication request diff -r 0a2997609f75 -r 7a555a68a9f2 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!!")),)