Commit 7361e9c4 authored by Cédric Le Ninivin's avatar Cédric Le Ninivin

Base: add getTransitionEffectiveDate and getTransitionDate

parent c899c714
......@@ -81,3 +81,56 @@ class Getter(BaseGetter):
return default
psyco.bind(__call__)
class GenericKeyGetter(Getter):
"""
Get 'key' property from Workflow History latest Transition. A
default value can be provided if needed.
"""
def __call__(self, instance, workflow_id, transition_id, default=None):
value_list = getattr(instance, self._list_accessor_name)(workflow_id, transition_id)
try:
return value_list[-1]
except IndexError:
return default
psyco.bind(__call__)
class GenericKeyListGetter(BaseGetter):
"""
List getter to get a key of a transition for a workflow
"""
def __init__(self, id, key):
self._id = id
self.__name__ = id
self._key = key
def __call__(self, instance, workflow_id, transition_id, *args):
try:
default = args[0]
except IndexError:
default = []
instance = aq_base(instance)
try:
workflow_history_dict_list = instance.workflow_history[workflow_id]
except (AttributeError, KeyError):
return default
else:
result_list = []
action_result_list = []
# Key may be on the action or the transition
action_transition_id = None if transition_id.endswith("_action") else transition_id + "_action"
for workflow_history_dict in workflow_history_dict_list:
if workflow_history_dict['action'] == transition_id:
value = workflow_history_dict.get(self._key)
if value:
result_list.append(value)
elif workflow_history_dict['action'] == action_transition_id:
value = workflow_history_dict.get(self._key)
if value:
action_result_list.append(value)
return result_list if result_list else action_result_list if action_result_list else default
psyco.bind(__call__)
\ No newline at end of file
......@@ -524,10 +524,29 @@ def initializePortalTypeDynamicWorkflowMethods(ptype_klass, portal_workflow):
workflow_dict = {}
interaction_workflow_dict = {}
for wf in portal_workflow.getWorkflowValueListFor(portal_type):
wf_id = wf.getId()
wf_type = wf.__class__.__name__
wf_transition_reference_list = wf.getTransitionReferenceList()
method_setting_list = [
('getTransitionDate', 'time'),
('getTransitionEffectiveDate', 'effective_time'),
]
for method_id, parameter in method_setting_list:
list_method_id = method_id + "List"
if not hasattr(ptype_klass, list_method_id):
method = WorkflowHistoryAccessor.GenericKeyListGetter(list_method_id, parameter)
ptype_klass.registerAccessor(method,
Permissions.AccessContentsInformation)
if not hasattr(ptype_klass, method_id):
method = WorkflowHistoryAccessor.GenericKeyGetter(method_id, list_method_id)
ptype_klass.registerAccessor(method,
Permissions.AccessContentsInformation)
if wf_type in ['DCWorkflowDefinition', 'Workflow']:
# Create state var accessor
# and generate methods that support the translation of workflow states
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment