Remove 'required' attribute on workflow 'comment' field
authorThierry Florac <thierry.florac@onf.fr>
Fri, 08 Dec 2017 10:43:03 +0100
changeset 306 7e7925d13e13
parent 305 b5967aacf4c1
child 307 01af83bd6054
Remove 'required' attribute on workflow 'comment' field
src/pyams_content/shared/common/zmi/workflow.py
--- a/src/pyams_content/shared/common/zmi/workflow.py	Fri Dec 08 10:42:11 2017 +0100
+++ b/src/pyams_content/shared/common/zmi/workflow.py	Fri Dec 08 10:43:03 2017 +0100
@@ -121,11 +121,20 @@
 class PublicationRequestForm(WorkflowContentTransitionForm):
     """Shared content publication request form"""
 
-    fields = field.Fields(IWorkflowTransitionInfo) + \
-             field.Fields(IWorkflowPublicationInfo).select('publication_effective_date', 'push_end_date',
-                                                           'publication_expiration_date') + \
-             field.Fields(IWorkflowRequestUrgencyInfo) + \
-             field.Fields(IWorkflowCommentInfo)
+    label_css_class = 'control-label col-md-4'
+    input_css_class = 'col-md-8'
+
+    @property
+    def fields(self):
+        pub_fields = ('publication_effective_date', 'push_end_date', 'publication_expiration_date')
+        state = IWorkflowState(self.context)
+        if state.version_id > 1:
+            pub_fields += ('displayed_publication_date', )
+        return field.Fields(IWorkflowTransitionInfo) + \
+               field.Fields(IWorkflowPublicationInfo).select(*pub_fields) + \
+               field.Fields(IWorkflowRequestUrgencyInfo) + \
+               field.Fields(IWorkflowCommentInfo)
+
     buttons = button.Buttons(IPublicationRequestButtons)
     ajax_handler = 'wf-propose.json'
 
@@ -135,15 +144,12 @@
         if 'publication_effective_date' in self.widgets:
             widget = self.widgets['publication_effective_date']
             widget.required = True
-            widget_date = tztime(pub_info.publication_effective_date or datetime.utcnow())
-            widget.value = widget_date.strftime('%d/%m/%y %H:%M')
+            widget.value = tztime(datetime.utcnow()).strftime('%d/%m/%y %H:%M')
         if ('push_end_date' in self.widgets) and pub_info.push_end_date:
             self.widgets['push_end_date'].value = tztime(pub_info.push_end_date).strftime('%d/%m/%y %H:%M')
         if ('publication_expiration_date' in self.widgets) and pub_info.publication_expiration_date:
             self.widgets['publication_expiration_date'].value = \
                 tztime(pub_info.publication_expiration_date).strftime('%d/%m/%y %H:%M')
-        if 'comment' in self.widgets:
-            self.widgets['comment'].required = True
 
     def createAndAdd(self, data):
         pub_info = IWorkflowPublicationInfo(self.context)
@@ -165,10 +171,6 @@
     data = event.data
     if not data.get('publication_effective_date'):
         event.form.widgets.errors += (Invalid(_("Publication start date is required")), )
-    comment = (data.get('comment') or '').strip()
-    if not comment:
-        event.form.widgets.errors += (Invalid(_("A comment is required")), )
-        event.form.widgets['comment'].error = Invalid(_("A comment is required"))
 
 
 @viewlet_config(name='wf-propose-message', context=IWfSharedContent, layer=IPyAMSLayer, view=PublicationRequestForm,
@@ -256,7 +258,8 @@
 
     def updateWidgets(self, prefix=None):
         super(PublicationRequestRefuseForm, self).updateWidgets(prefix)
-        self.widgets['comment'].required = True
+        if 'comment' in self.widgets:
+            self.widgets['comment'].required = True
 
 
 @view_config(name='wf-refuse.json', context=IWfSharedContent, request_type=IPyAMSLayer,
@@ -309,10 +312,19 @@
 class PublicationForm(WorkflowContentTransitionForm):
     """Shared content publication form"""
 
-    fields = field.Fields(IWorkflowTransitionInfo) + \
-             field.Fields(IWorkflowPublicationInfo).select('publication_effective_date', 'push_end_date',
-                                                           'publication_expiration_date') + \
-             field.Fields(IWorkflowCommentInfo)
+    label_css_class = 'control-label col-md-4'
+    input_css_class = 'col-md-8'
+
+    @property
+    def fields(self):
+        pub_fields = ('publication_effective_date', 'push_end_date', 'publication_expiration_date')
+        state = IWorkflowState(self.context)
+        if state.version_id > 1:
+            pub_fields += ('displayed_publication_date', )
+        return field.Fields(IWorkflowTransitionInfo) + \
+               field.Fields(IWorkflowPublicationInfo).select(*pub_fields) + \
+               field.Fields(IWorkflowCommentInfo)
+
     buttons = button.Buttons(IPublicationButtons)
     ajax_handler = 'wf-publish.json'
 
@@ -397,7 +409,8 @@
 
     def updateWidgets(self, prefix=None):
         super(PublicationRetireRequestForm, self).updateWidgets(prefix)
-        self.widgets['comment'].required = True
+        if 'comment' in self.widgets:
+            self.widgets['comment'].required = True
 
 
 @view_config(name='wf-retiring.json', context=IWfSharedContent, request_type=IPyAMSLayer,