# HG changeset patch # User Thierry Florac # Date 1444297092 -7200 # Node ID ceca681f8c3a5ec83c3d3518c0a81c4a41eab9f3 # Parent 182f33bba91d99d83df4f52c59944acc3f0df1c9 Allow several states in "has_version" method arguments diff -r 182f33bba91d -r ceca681f8c3a src/pyams_workflow/versions.py --- a/src/pyams_workflow/versions.py Thu Oct 08 11:37:30 2015 +0200 +++ b/src/pyams_workflow/versions.py Thu Oct 08 11:38:12 2015 +0200 @@ -48,6 +48,7 @@ source_version = FieldProperty(IWorkflowStateHistoryItem['source_version']) source_state = FieldProperty(IWorkflowStateHistoryItem['source_state']) target_state = FieldProperty(IWorkflowStateHistoryItem['target_state']) + transition_id = FieldProperty(IWorkflowStateHistoryItem['transition_id']) transition = FieldProperty(IWorkflowStateHistoryItem['transition']) principal = FieldProperty(IWorkflowStateHistoryItem['principal']) comment = FieldProperty(IWorkflowStateHistoryItem['comment']) @@ -65,6 +66,7 @@ _state = None _state_date = FieldProperty(IWorkflowState['state_date']) _state_principal = FieldProperty(IWorkflowState['state_principal']) + state_urgency = FieldProperty(IWorkflowState['state_urgency']) def __init__(self): self.history = PersistentList() @@ -102,6 +104,7 @@ source_state=translate(workflow.states.getTerm(event.source).title) if event.source else None, target_state=translate(workflow.states.getTerm(event.destination).title), + transition_id=event.transition.transition_id, transition=translate(event.transition.title), principal=request.principal.id, comment=event.comment) @@ -118,6 +121,7 @@ source_version=IWorkflowState(event.old_object).version_id, source_state=translate(workflow.states.getTerm(event.source).title), target_state=translate(workflow.states.getTerm(event.destination).title), + transition_id=event.transition.transition_id, transition=translate(event.transition.title), principal=request.principal.id, comment=event.comment) @@ -217,10 +221,15 @@ versions.append(version_id) self.versions_by_state[state] = versions - def has_version(self, state): - if state is None: - state = '__none__' - return bool(self.versions_by_state.get(state, ())) + def has_version(self, states): + if states is None: + states = '__none__' + if not isinstance(states, (list, tuple, set)): + states = {states} + for state in states: + if bool(self.versions_by_state.get(state, ())): + return True + return False def remove_version(self, version_id, state='deleted', comment=None): if str(version_id) not in self: