Update workflow-related summary
authorThierry Florac <thierry.florac@onf.fr>
Fri, 08 Dec 2017 10:43:36 +0100
changeset 307 01af83bd6054
parent 306 7e7925d13e13
child 308 adc7fa946d13
Update workflow-related summary
src/pyams_content/shared/common/zmi/summary.py
--- a/src/pyams_content/shared/common/zmi/summary.py	Fri Dec 08 10:43:03 2017 +0100
+++ b/src/pyams_content/shared/common/zmi/summary.py	Fri Dec 08 10:43:36 2017 +0100
@@ -22,7 +22,8 @@
 from pyams_skin.interfaces import IInnerPage
 from pyams_skin.layer import IPyAMSLayer
 from pyams_utils.interfaces import VIEW_SYSTEM_PERMISSION
-from pyams_workflow.interfaces import IWorkflowState, IWorkflow, IWorkflowPublicationInfo, IWorkflowStateHistoryItem
+from pyams_workflow.interfaces import IWorkflowState, IWorkflow, IWorkflowPublicationInfo, IWorkflowStateHistoryItem, \
+    IWorkflowVersions
 from z3c.form.interfaces import DISPLAY_MODE, IDataConverter
 
 # import packages
@@ -127,6 +128,12 @@
     legend = _("Publication and retire dates")
     weight = 20
 
+    def __new__(cls, context, request, form):
+        info = IWorkflowPublicationInfo(context)
+        if not info.publication_effective_date:
+            return None
+        return InnerAdminDisplayForm.__new__(cls)
+
     fields = field.Fields(IWorkflowPublicationInfo).select('publication_effective_date', 'push_end_date',
                                                            'publication_expiration_date', 'displayed_publication_date')
 
@@ -177,18 +184,12 @@
     def updateWidgets(self, prefix=None):
         super(SharedContentWorkflowHistorySummary, self).updateWidgets(prefix)
         workflow = IWorkflow(self.context)
-        state = IWorkflowState(self.context)
-        pub_date = tztime(state.get_first_state_date(workflow.published_states))
-        if pub_date is None:
-            value = ''
-        else:
-            now = tztime(datetime.utcnow())
-            pub_info = IWorkflowPublicationInfo(self.context)
-            if (pub_info.publication_effective_date is None) or (pub_date >= pub_info.publication_effective_date):
-                value = format_datetime(tztime(pub_date))
-            else:
-                if pub_info.publication_effective_date < now:
-                    value = ''
-                else:
-                    value = format_datetime(tztime(pub_info.publication_effective_date))
+        versions = IWorkflowVersions(self.context)
+        value = ''
+        for version in versions.get_versions():
+            state = IWorkflowState(version)
+            pub_date = tztime(state.get_first_state_date(workflow.published_states))
+            if pub_date is not None:
+                value = format_datetime(pub_date)
+                break
         self.widgets['first_publication_date'].value = value