quick search:
 

Get Worklist Info for Workflows

Submitted by: runyaga
Last Edited: 2004-10-14

Category: CMF

Average rating is: 0.0 out of 5 (0 ratings)

Description:
This recipe *REQUIRES* CMF and DCWorkflow

If you want to get information about Worklists. Its not very simple.
Here is a recipe that provide a method (external) or you can bind
it to the portal_workflow tool and use it over and over again.

getWorklists() trauls through all worklist info and returns it
back in a easy to use fashion. This is for when you want to use
worklist functionality w/o the actions_box fuss (as we need to do
in Plone).

should probably be renamed to getWorklistsInfo() for consistency?


Source (Text):
#in $ZOPE/Extensions create availableWorkflists.py, paste the below in

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)

#in the root of your CMF create a External method
#module: availableWorkflists
#function: getWorklists

#the Script(Python) I use to find out what objects I can review are:
wf_wlist_map = context.getWorklists() #getWorklists is currently a external method ;(
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_objs

ERROR: EOF in multi-line statement


Explanation:
Audience: Intermediate CMF Hacker
Lesson: Python uses consistent, simple data structures repeadly.
How it works:
creates a map for each workflow_id that is in workflow_tool,
makes a sequence for this map that contains dictionaries populated
with individual workflist information (see Description)

*you may* have a problem w/ the 'guard' element -- not sure if its restricted.


Comments:

No Comments