Changed summary fields
authorThierry Florac <thierry.florac@onf.fr>
Wed, 12 Jul 2017 11:52:02 +0200
changeset 110 991135437798
parent 109 56ed1a90e8e6
child 111 dfa050606268
Changed summary fields
src/pyams_content/shared/common/zmi/summary.py
--- a/src/pyams_content/shared/common/zmi/summary.py	Wed Jul 12 11:51:04 2017 +0200
+++ b/src/pyams_content/shared/common/zmi/summary.py	Wed Jul 12 11:52:02 2017 +0200
@@ -16,27 +16,27 @@
 # import standard library
 
 # import interfaces
-from pyams_content.interfaces import IBaseContentInfo
 from pyams_content.shared.common.interfaces import IWfSharedContent, IWfSharedContentRoles, ISharedTool
 from pyams_form.interfaces.form import IWidgetForm, IInnerTabForm, IInnerSubForm
-from pyams_sequence.interfaces import ISequentialIdInfo, ISequentialIntIds
 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
+from pyams_workflow.interfaces import IWorkflowState, IWorkflow, IWorkflowPublicationInfo, IWorkflowStateHistoryItem
+from z3c.form.interfaces import DISPLAY_MODE, IDataConverter
 
 # import packages
 from pyams_content.shared.common.zmi.header import SharedContentHeaderContentProvider
 from pyams_pagelet.pagelet import pagelet_config
+from pyams_security.utility import get_principal
 from pyams_utils.adapter import adapter_config
 from pyams_utils.date import format_datetime
-from pyams_utils.registry import get_utility
 from pyams_utils.timezone import tztime
 from pyams_utils.traversing import get_parent
 from pyams_utils.url import absolute_url
 from pyams_viewlet.viewlet import contentprovider_config
-from pyams_zmi.form import AdminDisplayForm, InnerAdminDisplayForm
+from pyams_zmi.form import AdminDisplayForm, InnerAdminDisplayForm, InnerAdminAddForm
 from z3c.form import field
+from z3c.form.browser.checkbox import SingleCheckBoxFieldWidget
 from zope.interface import implementer, Interface
 
 from pyams_content import _
@@ -77,58 +77,104 @@
     fields = field.Fields(Interface)
 
 
-@adapter_config(name='dublincore-version-summary',
+@adapter_config(name='workflow-waiting-state',
+                context=(IWfSharedContent, IPyAMSLayer, SharedContentDublinCoreSummary),
+                provides=IInnerSubForm)
+class SharedContentWorkflowWaitingState(InnerAdminAddForm):
+    """Shared content workflow waiting state summary"""
+
+    legend = _("Requested action")
+    weight = 10
+
+    mode = DISPLAY_MODE
+
+    def __new__(cls, context, request, form):
+        workflow = IWorkflow(context)
+        state = IWorkflowState(context)
+        if state.state not in workflow.waiting_states:
+            return None
+        return InnerAdminDisplayForm.__new__(cls)
+
+    fields = field.Fields(IWorkflowState).select('state', 'state_urgency') + \
+             field.Fields(IWorkflowStateHistoryItem).select('comment')
+
+    def updateWidgets(self, prefix=None):
+        super(SharedContentWorkflowWaitingState, self).updateWidgets(prefix)
+        state = IWorkflowState(self.context)
+        if 'state' in self.widgets:
+            translate = self.request.localizer.translate
+            workflow = IWorkflow(self.context)
+            self.widgets['state'].value = translate(_("{state} {date} by {principal}")).format(
+                state=translate(workflow.get_state_label(state.state)),
+                date=format_datetime(state.state_date),
+                principal=get_principal(self.request, state.state_principal).title
+            )
+        if 'state_urgency' in self.widgets:
+            converter = IDataConverter(self.widgets['state_urgency'])
+            self.widgets['state_urgency'].value = converter.toWidgetValue(state.state_urgency)
+        if 'comment' in self.widgets:
+            history_item = state.history[-1]
+            self.widgets['comment'].label = _("Associated comment")
+            self.widgets['comment'].value = history_item.comment
+
+
+@adapter_config(name='workflow-publication-state',
                 context=(IWfSharedContent, IPyAMSLayer, SharedContentDublinCoreSummary),
                 provides=IInnerSubForm)
-class SharedContentDublinCoreVersionSummary(InnerAdminDisplayForm):
-    """Shared content version DublinCore summary"""
+class SharedContentWorkflowPublicationState(InnerAdminDisplayForm):
+    """Shared content workflow publication state summary"""
 
-    legend = _("About this version")
-    weight = 1
+    legend = _("Publication and retire dates")
+    weight = 20
+
+    fields = field.Fields(IWorkflowPublicationInfo).select('publication_effective_date', 'push_end_date',
+                                                           'publication_expiration_date', 'displayed_publication_date')
+
 
-    @property
-    def fields(self):
-        fields = field.Fields(ISequentialIdInfo).select('hex_oid') + \
-                 field.Fields(IWorkflowState).select('version_id') + \
-                 field.Fields(IWfSharedContentRoles).select('owner') + \
-                 field.Fields(IWfSharedContent).select('creator') + \
-                 field.Fields(IBaseContentInfo).select('created_date') + \
-                 field.Fields(IWorkflowPublicationInfo).select('publication') + \
-                 field.Fields(IBaseContentInfo).select('modified_date') + \
-                 field.Fields(IWfSharedContent).select('last_modifier', 'modifiers')
-        workflow = IWorkflow(self.context)
-        if IWorkflowState(self.context).state not in workflow.published_states:
-            fields = fields.omit('publication')
-        return fields
+@adapter_config(name='workflow-version-summary',
+                context=(IWfSharedContent, IPyAMSLayer, SharedContentDublinCoreSummary),
+                provides=IInnerSubForm)
+class SharedContentWorkflowVersionSummary(InnerAdminDisplayForm):
+    """Shared content workflow version summary"""
+
+    legend = _("Current version")
+    weight = 30
+
+    fields = field.Fields(IWorkflowState).select('version_id', 'state') + \
+             field.Fields(IWfSharedContent).select('creation_label') + \
+             field.Fields(IWfSharedContentRoles).select('owner') + \
+             field.Fields(IWfSharedContent).select('last_update_label') + \
+             field.Fields(IWfSharedContent).select('modifiers')
 
     def updateWidgets(self, prefix=None):
-        super(SharedContentDublinCoreVersionSummary, self).updateWidgets(prefix)
-        sequence = get_utility(ISequentialIntIds)
-        self.widgets['hex_oid'].value = sequence.get_short_oid(ISequentialIdInfo(self.context).oid)
-        workflow = IWorkflow(self.context)
-        self.widgets['version_id'].label = _("Version")
-        self.widgets['version_id'].value = '{version_id} - {status}'.format(
-            version_id=IWorkflowState(self.context).version_id,
-            status=self.request.localizer.translate(workflow.get_state_label(IWorkflowState(self.context).state)))
-        info = IBaseContentInfo(self.context)
-        self.widgets['created_date'].value = format_datetime(tztime(info.created_date))
-        self.widgets['modified_date'].value = format_datetime(tztime(info.modified_date))
+        super(SharedContentWorkflowVersionSummary, self).updateWidgets(prefix)
+        if 'version_id' in self.widgets:
+            self.widgets['version_id'].label = _("Version")
+        if 'state' in self.widgets:
+            translate = self.request.localizer.translate
+            workflow = IWorkflow(self.context)
+            workflow_state = IWorkflowState(self.context)
+            history_item = workflow_state.history[-1]
+            self.widgets['state'].value = translate(_("{state} since {date}, by {principal}")).format(
+                state=translate(workflow.get_state_label(workflow_state.state)),
+                date=format_datetime(tztime(history_item.date)),
+                principal=get_principal(self.request, history_item.principal).title)
 
 
-@adapter_config(name='dublincore-history-summary',
+@adapter_config(name='workflow-history-summary',
                 context=(IWfSharedContent, IPyAMSLayer, SharedContentDublinCoreSummary),
                 provides=IInnerSubForm)
-class SharedContentDublinCoreHistorySummary(InnerAdminDisplayForm):
-    """Shared content history DublinCore summary"""
+class SharedContentWorkflowHistorySummary(InnerAdminDisplayForm):
+    """Shared content workflow history summary"""
 
     legend = _("Content history")
 
     fields = field.Fields(IWfSharedContent).select('first_owner') + \
              field.Fields(IWorkflowPublicationInfo).select('first_publication_date')
 
-    weight = 2
+    weight = 40
 
     def updateWidgets(self, prefix=None):
-        super(SharedContentDublinCoreHistorySummary, self).updateWidgets(prefix)
+        super(SharedContentWorkflowHistorySummary, self).updateWidgets(prefix)
         info = IWorkflowPublicationInfo(self.context)
         self.widgets['first_publication_date'].value = format_datetime(tztime(info.first_publication_date))