Updated states labels
authorThierry Florac <thierry.florac@onf.fr>
Mon, 18 Jan 2016 16:10:52 +0100
changeset 10 cd69b40debd7
parent 9 f6739a79912f
child 11 20bb3019612a
Updated states labels
src/pyams_content/workflow/__init__.py
--- a/src/pyams_content/workflow/__init__.py	Mon Jan 18 16:09:49 2016 +0100
+++ b/src/pyams_content/workflow/__init__.py	Mon Jan 18 16:10:52 2016 +0100
@@ -19,15 +19,16 @@
 # import interfaces
 from pyams_content.interfaces import MANAGE_SITE_ROOT_PERMISSION, MANAGE_CONTENT_PERMISSION, PUBLISH_CONTENT_PERMISSION, \
     CREATE_CONTENT_PERMISSION
-from pyams_content.shared.common.interfaces import IWfSharedContentRoles, IManagerRestrictions
+from pyams_content.shared.common.interfaces import IWfSharedContentRoles, IManagerRestrictions, IWfSharedContent
 from pyams_content.workflow.interfaces import IContentWorkflow
-from pyams_security.interfaces import IRoleProtectedObject, ISecurityManager
+from pyams_security.interfaces import IRoleProtectedObject
 from pyams_workflow.interfaces import IWorkflow, AUTOMATIC, IWorkflowPublicationInfo, SYSTEM, IWorkflowVersions, \
     IWorkflowState, ObjectClonedEvent, IWorkflowInfo, IWorkflowStateLabel
 
 # import packages
 from pyams_utils.adapter import adapter_config, ContextAdapter
-from pyams_utils.registry import utility_config, get_utility
+from pyams_utils.date import format_datetime
+from pyams_utils.registry import utility_config
 from pyams_utils.request import check_request
 from pyams_workflow.workflow import Transition, Workflow
 from pyramid.threadlocal import get_current_registry
@@ -90,13 +91,13 @@
                  _("Archived"),
                  _("Deleted"))
 
-STATES_HEADERS = {DRAFT: _("draft created by {principal}"),
-                  PROPOSED: _("publication requested by {principal}"),
-                  PUBLISHED: _("published by {principal}"),
-                  RETIRING: _("retiring requested by {principal}"),
-                  RETIRED: _("retired by {principal}"),
-                  ARCHIVING: _("archiving requested by {principal}"),
-                  ARCHIVED: _("archived by {principal}")}
+STATES_HEADERS = {DRAFT: _("draft created"),
+                  PROPOSED: _("publication requested"),
+                  PUBLISHED: _("published"),
+                  RETIRING: _("retiring requested"),
+                  RETIRED: _("retired"),
+                  ARCHIVING: _("archiving requested"),
+                  ARCHIVED: _("archived")}
 
 STATES_VOCABULARY = SimpleVocabulary([SimpleTerm(STATES_IDS[i], title=t)
                                       for i, t in enumerate(STATES_LABELS)])
@@ -180,13 +181,15 @@
 
 def publish_action(wf, context):
     """Publish version"""
+    request = check_request()
+    translate = request.localizer.translate
     IWorkflowPublicationInfo(context).publication_date = datetime.utcnow()
-    translate = check_request().localizer.translate
     version_id = IWorkflowState(context).version_id
     for version in IWorkflowVersions(context).get_versions((PUBLISHED, RETIRING, RETIRED, ARCHIVING)):
         if version is not context:
             IWorkflowInfo(version).fire_transition_toward('archived',
                                                           comment=translate(_("Published version {0}")).format(version_id))
+    IWfSharedContent(context).publisher = request.principal.id
 
 
 def archive_action(wf, context):
@@ -519,11 +522,11 @@
         if request is None:
             request = check_request()
         translate = request.localizer.translate
-        security = get_utility(ISecurityManager)
         state = IWorkflowState(content)
         state_label = translate(STATES_HEADERS[state.state])
         if format:
-            state_label = state_label.format(principal=security.get_principal(state.state_principal).title)
+            state_label = translate(_('{state} {date}')).format(state=state_label,
+                                                                date=format_datetime(state.state_date))
         return state_label
 
 
@@ -536,14 +539,17 @@
         if request is None:
             request = check_request()
         translate = request.localizer.translate
-        security = get_utility(ISecurityManager)
         state = IWorkflowState(content)
         if len(state.history) == 1:
-            state_label = translate(STATES_HEADERS[state.state])
+            if state.version_id == 1:
+                state_label = translate(STATES_HEADERS[state.state])
+            else:
+                state_label = translate(_("new version created"))
         else:
-            state_label = translate(_('publication refused by {principal}'))
+            state_label = translate(_('publication refused'))
         if format:
-            state_label = state_label.format(principal=security.get_principal(state.state_principal).title)
+            state_label = translate(_('{state} {date}')).format(state=state_label,
+                                                                date=format_datetime(state.state_date))
         return state_label