Source (Text):
from Products.CMFCore.utils import getToolByName
def getWorklists(self):
""" instead of manually scraping actions_box, lets:
query for all worklists in all workflow definitions.
Returns a dictionary whos value is sequence of dictionaries
i.e. map[workflow_id]=(workflow definition map, )
each workflow defintion map contains the following:
(worklist)id, guard (Guard instance), catalog_vars (mapping), actbox_name (actions box label), and actbox_url (actions box url)
"""
wf_tool=getToolByName(self, 'portal_workflow')
wf_with_wlists = {}
for id in wf_tool.getWorkflowIds():
wf=wf_tool.getWorkflowById(id)
if hasattr(wf, 'worklists'):
wlists = []
for worklist in wf.worklists._objects:
wlist_def=wf.worklists._mapping[worklist['id']]
a_wlist = { 'id':worklist['id']
, 'guard' : wlist_def.getGuard()
, 'catalog_vars' : wlist_def.var_matches }
name = getattr(wlist_def, 'actbox_name', None)
if name: a_wlist['name']=name
url=getattr(wlist_def, 'actbox_url', None)
if url: a_wlist['url']=url
wlists.append(a_wlist)
wf_with_wlists[id]=wlists
return wf_with_wlists
def testGettingWorklists(self):
wf_tool=getToolByName(self, 'portal_workflow')
if not hasattr(wf_tool, 'getWorklists'):
wf_tool.getWorklists = getWorklists
for wflow_id, wlist_seq in wf_tool.getWorklists(self).items():
for wlist in wlist_seq:
permission=wlist['guard'].getPermissionsText()
permission)
wf_wlist_map = context.getWorklists()
catalog=context.portal_catalog
avail_objs = []
for wlist_map_sequence in wf_wlist_map.values():
for wlist_map in wlist_map_sequence:
permission=wlist_map['guard_permissions']
catalog_vars=wlist_map['catalog_vars']
if context.portal_membership.checkPermission(permission, container):
for result in catalog.searchResults(catalog_vars):
avail_objs.append(result.getObject())
return avail_objsERROR: EOF in multi-line statement
|