Commit a696a77f authored by Julien Muchembled's avatar Julien Muchembled

On transitions, display source states instead of all states. (+ refactoring)

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@25622 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 06547f56
......@@ -93,7 +93,7 @@ class DCWorkflowDocumentationHelper(DocumentationHelper):
for role in getRoleList(self.getDocumentedObject())]
def getStateUriList(self):
return ['%s/states#%s' % (self.uri, state)
return ['%s/states/%s' % (self.uri, state)
for state in sorted(self.getDocumentedObject().states.objectIds())]
security.declareProtected(Permissions.AccessContentsInformation, 'getStateItemList')
......@@ -109,56 +109,17 @@ class DCWorkflowDocumentationHelper(DocumentationHelper):
item_list.append(helper)
return item_list
security.declareProtected(Permissions.AccessContentsInformation, 'getTransitionIdList')
def getTransitionIdList(self):
"""
"""
transition_list = []
transitions = getattr(self.getDocumentedObject(), 'transitions', None)
if transitions is not None:
for transition in transitions.objectValues():
transition_list.append(transition.getId())
return transition_list
security.declareProtected(Permissions.AccessContentsInformation, 'getTransitionItemList')
def getTransitionItemList(self):
"""
"""
transition_list = []
trigger_type_list = ['Automatic','Initiated by user action','Initiated by WorkflowMethod']
transitions = getattr(self.getDocumentedObject(), 'transitions', None)
if transitions is not None:
for transition in self.getDocumentedObject().transitions.objectValues():
guard_roles = ""
guard = dir(transition.guard)
if hasattr(transition.guard, '__dict__'):
if 'roles' in transition.guard.__dict__.keys():
guard_roles = ', '.join(role for role in transition.guard.__dict__['roles'])
transition_list.append((transition.getId(),
getattr(transition, "title", ""),
trigger_type_list[transition.trigger_type],
getattr(transition, "description", ""),
guard_roles
))
return transition_list
security.declareProtected(Permissions.AccessContentsInformation, 'getTransitionUriList')
def getTransitionUriList(self):
"""
"""
transition_id_list = self.getTransitionIdList()
return map(lambda x: ('%s/transitions/%s' % (self.uri, x)), transition_id_list)
return ['%s/transitions/%s' % (self.uri, transition)
for transition
in sorted(self.getDocumentedObject().transitions.objectIds())]
security.declareProtected(Permissions.AccessContentsInformation, 'getTransitionURIList')
def getTransitionURIList(self):
security.declareProtected(Permissions.AccessContentsInformation, 'getTransitionItemList')
def getTransitionItemList(self, **kw):
"""
"""
transition_item_list = self.getTransitionItemList()
klass = self.getDocumentedObject().__class__
class_name = klass.__name__
module = klass.__module__
uri_prefix = '%s.%s.' % (module, class_name)
return map(lambda x: ('%s%s' % (uri_prefix, x[0]), x[1], x[2], x[3], x[4]), transition_item_list)
return [self.getDocumentationHelper('DCWorkflowTransitionDocumentationHelper', uri)
for uri in self.getTransitionUriList()]
security.declareProtected(Permissions.AccessContentsInformation, 'getVariableIdList')
def getVariableIdList(self):
......
......@@ -46,12 +46,15 @@ class DCWorkflowStateDocumentationHelper(DocumentationHelper):
"""
return "Workflow State"
security.declareProtected(Permissions.AccessContentsInformation, 'getTransitionList')
def getTransitionList(self):
security.declareProtected(Permissions.AccessContentsInformation, 'getTransitionItemList')
def getTransitionItemList(self, **kw):
"""
Returns list of possible transitions from this state
"""
return self.getDocumentedObject().transitions
state = self.getDocumentedObject()
base_uri = '/'.join(state.getPhysicalPath()[:-2] + ('transitions', ''))
return [self.getDocumentationHelper('DCWorkflowTransitionDocumentationHelper',
base_uri + id)
for id in state.transitions]
security.declareProtected(Permissions.AccessContentsInformation, 'getRoleList')
def getRoleList(self):
......
......@@ -45,6 +45,14 @@ class DCWorkflowTransitionDocumentationHelper(DocumentationHelper):
"""
return "Workflow Transition"
security.declareProtected(Permissions.AccessContentsInformation, 'getTitle')
def getTitle(self):
"""
Returns the title of the documentation helper
"""
return DocumentationHelper.getTitle(self) \
or self.getDocumentedObject().actbox_name
security.declareProtected(Permissions.AccessContentsInformation, 'getNewStateId')
def getNewStateId(self):
"""
......@@ -75,24 +83,31 @@ class DCWorkflowTransitionDocumentationHelper(DocumentationHelper):
"""
return getattr(self.getDocumentedObject(), "after_script_name", '')
security.declareProtected(Permissions.AccessContentsInformation, 'getRoleColumnList')
def getRoleColumnList(self):
"""
"""
return self.getDocumentationHelper('DCWorkflowDocumentationHelper',
self.uri.rsplit('/',2)[0]) \
.getRoleColumnList()
security.declareProtected(Permissions.AccessContentsInformation, 'getAvailableStateIds')
def getAvailableStateIds(self):
def getStateItemList(self, **kw):
"""
Returns available states in the workflow
"""
return self.getDocumentedObject().getAvailableStateIds()
workflow_uri, transitions, transition_id = self.uri.rsplit('/',2)
helper = self.getDocumentationHelper('DCWorkflowDocumentationHelper', workflow_uri)
return [state for state in helper.getStateItemList(**kw)
if transition_id in state.getDocumentedObject().transitions]
security.declareProtected(Permissions.AccessContentsInformation, 'getGuardRoles')
def getGuardRoles(self):
"""
Returns roles to pass this transition
"""
role_list = ()
if hasattr(self.getDocumentedObject(),'guard'):
dir(self.getDocumentedObject().guard)
if hasattr(self.getDocumentedObject().guard, '__dict__'):
if 'roles' in self.getDocumentedObject().guard.__dict__.keys():
role_list = self.getDocumentedObject().guard.__dict__['roles']
return ', '.join(role for role in role_list)
guard = getattr(self.getDocumentedObject(), 'guard', None)
if guard is not None:
return ', '.join(guard.roles)
InitializeClass(DCWorkflowTransitionDocumentationHelper)
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