Updated workflow history management
authorThierry Florac <thierry.florac@onf.fr>
Mon, 11 Sep 2017 14:32:50 +0200
changeset 38 ecaf0ac4b04e
parent 37 2b8636f18d39
child 39 0e411b2c6501
Updated workflow history management
src/pyams_workflow/zmi/versions.py
--- a/src/pyams_workflow/zmi/versions.py	Mon Sep 11 14:28:08 2017 +0200
+++ b/src/pyams_workflow/zmi/versions.py	Mon Sep 11 14:32:50 2017 +0200
@@ -16,7 +16,6 @@
 # import standard library
 
 # import interfaces
-from pyams_security.interfaces import ISecurityManager
 from pyams_skin.interfaces import IInnerPage
 from pyams_skin.layer import IPyAMSLayer
 from pyams_utils.interfaces import VIEW_SYSTEM_PERMISSION
@@ -27,12 +26,13 @@
 
 # import packages
 from pyams_pagelet.pagelet import pagelet_config
+from pyams_security.principal import MissingPrincipal
+from pyams_security.utility import get_principal
 from pyams_skin.container import ContainerView
 from pyams_skin.table import BaseTable, I18nColumn
 from pyams_skin.viewlet.menu import MenuItem
 from pyams_utils.adapter import adapter_config, ContextRequestViewAdapter
 from pyams_utils.date import format_datetime, SH_DATETIME_FORMAT
-from pyams_utils.registry import query_utility
 from pyams_utils.text import text_to_html
 from pyams_viewlet.viewlet import viewlet_config
 from pyams_zmi.layer import IAdminLayer
@@ -96,7 +96,7 @@
         return format_datetime(item.date, SH_DATETIME_FORMAT, request=self.request)
 
 
-@adapter_config(name='target', context=(Interface, IPyAMSLayer, WorkflowVersionHistoryTable), provides=IColumn)
+@adapter_config(name='state', context=(Interface, IPyAMSLayer, WorkflowVersionHistoryTable), provides=IColumn)
 class WorkflowVersionHistoryTargetColumn(I18nColumn, GetAttrColumn):
     """Workflow version history source column"""
 
@@ -104,6 +104,19 @@
     attrName = 'target_state'
     weight = 5
 
+    def getValue(self, obj):
+        state = super(WorkflowVersionHistoryTargetColumn, self).getValue(obj)
+        workflow = IWorkflow(self.context, None)
+        if workflow is None:
+            return state
+        try:
+            term = workflow.states.getTerm(state)
+        except LookupError:
+            return state or '--'
+        else:
+            translate = self.request.localizer.translate
+            return translate(term.title)
+
 
 @adapter_config(name='name', context=(Interface, IPyAMSLayer, WorkflowVersionHistoryTable), provides=IColumn)
 class WorkflowVersionHistoryPrincipalColumn(I18nColumn, GetAttrColumn):
@@ -114,11 +127,11 @@
     weight = 10
 
     def renderCell(self, item):
-        manager = query_utility(ISecurityManager)
-        if manager is not None:
-            return manager.get_principal(item.principal).title
+        principal = get_principal(self.request, item.principal)
+        if isinstance(principal, MissingPrincipal):
+            return '--'
         else:
-            return item.principal
+            return principal.title
 
 
 @adapter_config(name='comment', context=(Interface, IPyAMSLayer, WorkflowVersionHistoryTable), provides=IColumn)