Back to index

plone3  3.1.7
Public Member Functions | Static Public Attributes | Static Private Attributes
CMFPlone.WorkflowTool.WorkflowTool Class Reference
Inheritance diagram for CMFPlone.WorkflowTool.WorkflowTool:
Inheritance graph
[legend]
Collaboration diagram for CMFPlone.WorkflowTool.WorkflowTool:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def flattenTransitions
def flattenTransitionsForPaths
def getTransitionsFor
def workflows_in_use
def getWorklists
def getWorklistsResults
def getChainForPortalType
def listWorkflows
def getTitleForStateOnType
def getTitleForTransitionOnType
def listWFStatesByTitle
def getChainFor

Static Public Attributes

 meta_type = ToolNames.WorkflowTool
tuple security = ClassSecurityInfo()
int plone_tool = 1
string toolicon = 'skins/plone_images/workflow_icon.gif'

Static Private Attributes

tuple __implements__ = (PloneBaseTool.__implements__, BaseTool.__implements__, )

Detailed Description

Definition at line 19 of file WorkflowTool.py.


Member Function Documentation

def CMFPlone.WorkflowTool.WorkflowTool.flattenTransitions (   self,
  objs,
  container = None 
)
this is really hokey - hold on!!

Definition at line 30 of file WorkflowTool.py.

00030 
00031     def flattenTransitions(self, objs, container=None):
00032         """ this is really hokey - hold on!!"""
00033         if hasattr(objs, 'startswith'):
00034             return ()
00035 
00036         # TODO Need to behave differently for paths
00037         if len(objs) and '/' in objs[0]:
00038             return self.flattenTransitionsForPaths(objs)
00039         transitions=[]
00040         t_names=[]
00041 
00042         if container is None:
00043             container = self
00044         for o in [getattr(container, oid, None) for oid in objs]:
00045             trans=()
00046             try:
00047                 trans=self.getTransitionsFor(o, container)
00048             except ConflictError:
00049                 raise
00050             except:
00051                 pass
00052             if trans:
00053                 for t in trans:
00054                     if t['name'] not in t_names:
00055                         transitions.append(t)
00056                         t_names.append(t['name'])
00057 
00058         return tuple(transitions[:])
00059 

Here is the call graph for this function:

Here is the caller graph for this function:

this is even more hokey!!

Definition at line 60 of file WorkflowTool.py.

00060 
00061     def flattenTransitionsForPaths(self, paths):
00062         """ this is even more hokey!!"""
00063         if hasattr(paths, 'startswith'):
00064             return ()
00065 
00066         transitions=[]
00067         t_names=[]
00068         portal = getToolByName(self, 'portal_url').getPortalObject()
00069 
00070         for o in [portal.restrictedTraverse(path) for path in paths]:
00071             trans=()
00072             try:
00073                 trans=self.getTransitionsFor(o, o.aq_inner.aq_parent)
00074             except ConflictError:
00075                 raise
00076             except:
00077                 pass
00078             if trans:
00079                 for t in trans:
00080                     if t['name'] not in t_names:
00081                         transitions.append(t)
00082                         t_names.append(t['name'])
00083 
00084         return tuple(transitions[:])

Here is the call graph for this function:

Here is the caller graph for this function:

Returns the chain that applies to the given object.
If we get a string as the ob parameter, use it as
the portal_type.

Definition at line 311 of file WorkflowTool.py.

00311 
00312     def getChainFor( self, ob ):
00313         """
00314         Returns the chain that applies to the given object.
00315         If we get a string as the ob parameter, use it as
00316         the portal_type.
00317         """
00318         return getMultiAdapter( (ob, self), IWorkflowChain )
00319 
00320 WorkflowTool.__doc__ = BaseTool.__doc__
00321 
00322 InitializeClass(WorkflowTool)

Here is the caller graph for this function:

def CMFPlone.WorkflowTool.WorkflowTool.getChainForPortalType (   self,
  pt_name,
  managescreen = 0 
)
Get a chain for a specific portal type.

Definition at line 240 of file WorkflowTool.py.

00240 
00241     def getChainForPortalType(self, pt_name, managescreen=0):
00242         """ Get a chain for a specific portal type.
00243         """
00244         if self._chains_by_type.has_key(pt_name):
00245             return self._chains_by_type[pt_name]
00246         else:
00247             # (Default) is _not_ a chain nor a workflow in a chain.
00248             if managescreen:
00249                 return '(Default)'
00250             else:
00251                 # Return the default chain.
00252                 return self._default_chain

Here is the caller graph for this function:

def CMFPlone.WorkflowTool.WorkflowTool.getTitleForStateOnType (   self,
  state_name,
  p_type 
)
Returns the workflow state title for a given state name,
   uses a portal_type to determine which workflow to use

Definition at line 260 of file WorkflowTool.py.

00260 
00261     def getTitleForStateOnType(self, state_name, p_type):
00262         """Returns the workflow state title for a given state name,
00263            uses a portal_type to determine which workflow to use
00264         """
00265         if state_name and p_type is not None:
00266             chain = self.getChainForPortalType(p_type)
00267             for wf_id in chain:
00268                 wf = self.getWorkflowById(wf_id)
00269                 if wf is not None:
00270                     states = wf.states
00271                     state = getattr(states, state_name, None)
00272                     if state is not None:
00273                         return getattr(aq_base(state), 'title', None) or state_name
00274         return state_name

Here is the call graph for this function:

def CMFPlone.WorkflowTool.WorkflowTool.getTitleForTransitionOnType (   self,
  trans_name,
  p_type 
)
Returns the workflow transition title for a given transition name,
   uses a portal_type to determine which workflow to use

Definition at line 276 of file WorkflowTool.py.

00276 
00277     def getTitleForTransitionOnType(self, trans_name, p_type):
00278         """Returns the workflow transition title for a given transition name,
00279            uses a portal_type to determine which workflow to use
00280         """
00281         if trans_name and p_type is not None:
00282             chain = self.getChainForPortalType(p_type)
00283             for wf_id in chain:
00284                 wf = self.getWorkflowById(wf_id)
00285                 if wf is not None:
00286                     transitions = wf.transitions
00287                     trans = getattr(transitions, trans_name, None)
00288                     if trans is not None:
00289                         return getattr(aq_base(trans), 'actbox_name', None) or trans_name
00290         return trans_name

Here is the call graph for this function:

def CMFPlone.WorkflowTool.WorkflowTool.getTransitionsFor (   self,
  obj = None,
  container = None,
  REQUEST = None 
)

Definition at line 86 of file WorkflowTool.py.

00086 
00087     def getTransitionsFor(self, obj=None, container=None, REQUEST=None):
00088         if type(obj) is type([]):
00089             return self.flattenTransitions(objs=obj, container=container)
00090         result = {}
00091         chain = self.getChainFor(obj)
00092         for wf_id in chain:
00093             wf = self.getWorkflowById(wf_id)
00094             if wf is not None:
00095                 sdef = wf._getWorkflowStateOf(obj)
00096                 if sdef is not None:
00097                     for tid in sdef.transitions:
00098                         tdef = wf.transitions.get(tid, None)
00099                         if tdef is not None and \
00100                            tdef.trigger_type == TRIGGER_USER_ACTION and \
00101                            tdef.actbox_name and \
00102                            wf._checkTransitionGuard(tdef, obj) and \
00103                            not result.has_key(tdef.id):
00104                             result[tdef.id] = {
00105                                     'id': tdef.id,
00106                                     'title': tdef.title,
00107                                     'title_or_id': tdef.title_or_id(),
00108                                     'description': tdef.description,
00109                                     'name': tdef.actbox_name,
00110                                     'url': tdef.actbox_url %
00111                                            {'content_url': obj.absolute_url(),
00112                                             'portal_url' : '',
00113                                             'folder_url' : ''}}
00114         return tuple(result.values())

Here is the call graph for this function:

Here is the caller graph for this function:

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), guard_permissions (permission of Guard instance),
    guard_roles (roles of Guard instance), catalog_vars (mapping), actbox_name (actions box label),
    actbox_url (actions box url) and types (list of portal types)

Definition at line 128 of file WorkflowTool.py.

00128 
00129     def getWorklists(self):
00130         """ instead of manually scraping actions_box, lets:
00131             query for all worklists in all workflow definitions.
00132             Returns a dictionary whos value is sequence of dictionaries
00133 
00134             i.e. map[workflow_id]=(workflow definition map, )
00135             each workflow defintion map contains the following:
00136             (worklist)id, guard (Guard instance), guard_permissions (permission of Guard instance),
00137             guard_roles (roles of Guard instance), catalog_vars (mapping), actbox_name (actions box label),
00138             actbox_url (actions box url) and types (list of portal types)
00139         """
00140         # We want to know which types use the workflows with worklists
00141         # This for example avoids displaying 'pending' of multiple workflows in the same worklist
00142         types_tool = getToolByName(self, 'portal_types')
00143         list_ptypes = types_tool.listContentTypes()
00144         types_by_wf = {} # wf:[list,of,types]
00145         for t in list_ptypes:
00146             for wf in self.getChainFor(t):
00147                 types_by_wf[wf] = types_by_wf.get(wf,[]) + [t]
00148 
00149         # Placeful stuff
00150         placeful_tool = getToolByName(self, 'portal_placeful_workflow', None)
00151         if placeful_tool is not None:
00152             for policy in placeful_tool.getWorkflowPolicies():
00153                 for t in list_ptypes:
00154                     chain = policy.getChainFor(t) or ()
00155                     for wf in chain:
00156                         types_by_wf[wf] = types_by_wf.get(wf,[]) + [t]
00157 
00158         wf_with_wlists = {}
00159         for id in self.getWorkflowIds():
00160             # the above list incomprehension merely _flattens_ nested sequences into 1 sequence
00161 
00162             wf=self.getWorkflowById(id)
00163             if hasattr(wf, 'worklists'):
00164                 wlists = []
00165                 for worklist in wf.worklists._objects:
00166                     wlist_def=wf.worklists._mapping[worklist['id']]
00167                     # Make the var_matches a dict instead of PersistentMapping to enable access from scripts
00168                     var_matches = {}
00169                     for key in wlist_def.var_matches.keys(): var_matches[key] = wlist_def.var_matches[key]
00170                     a_wlist = { 'id':worklist['id']
00171                               , 'guard' : wlist_def.getGuard()
00172                               , 'guard_permissions' : wlist_def.getGuard().permissions
00173                               , 'guard_roles' : wlist_def.getGuard().roles
00174                               , 'catalog_vars' : var_matches
00175                               , 'name' : getattr(wlist_def, 'actbox_name', None)
00176                               , 'url' : getattr(wlist_def, 'actbox_url', None)
00177                               , 'types' : types_by_wf.get(id,[]) }
00178                     wlists.append(a_wlist)
00179                 # yes, we can duplicates, we filter duplicates out on the calling PyhtonScript client
00180                 wf_with_wlists[id]=wlists
00181 
00182         return wf_with_wlists

Here is the call graph for this function:

Return all the objects concerned by one or more worklists

This method replace 'getWorklists' by implementing the whole worklists
work for the script.
An object is returned only once, even if is return by several worklists.
Make the whole work as expensive it is.

Definition at line 184 of file WorkflowTool.py.

00184 
00185     def getWorklistsResults(self):
00186         """Return all the objects concerned by one or more worklists
00187 
00188         This method replace 'getWorklists' by implementing the whole worklists
00189         work for the script.
00190         An object is returned only once, even if is return by several worklists.
00191         Make the whole work as expensive it is.
00192         """
00193         sm = getSecurityManager()
00194         # We want to know which types use the workflows with worklists
00195         # This for example avoids displaying 'pending' of multiple workflows in the same worklist
00196         types_tool = getToolByName(self, 'portal_types')
00197         catalog = getToolByName(self, 'portal_catalog')
00198 
00199         list_ptypes = types_tool.listContentTypes()
00200         types_by_wf = {} # wf:[list,of,types]
00201         for t in list_ptypes:
00202             for wf in self.getChainFor(t):
00203                 types_by_wf[wf] = types_by_wf.get(wf, []) + [t]
00204 
00205         # PlacefulWorkflowTool will give us other results
00206         placeful_tool = getToolByName(self, 'portal_placeful_workflow', None)
00207         if placeful_tool is not None:
00208             for policy in placeful_tool.getWorkflowPolicies():
00209                 for t in list_ptypes:
00210                     chain = policy.getChainFor(t) or ()
00211                     for wf in chain:
00212                         types_by_wf[wf] = types_by_wf.get(wf, []) + [t]
00213 
00214         objects_by_path = {}
00215         for id in self.getWorkflowIds():
00216 
00217             wf=self.getWorkflowById(id)
00218             if hasattr(wf, 'worklists'):
00219                 wlists = []
00220                 for worklist in wf.worklists._objects:
00221                     wlist_def=wf.worklists._mapping[worklist['id']]
00222                     # Make the var_matches a dict instead of PersistentMapping to enable access from scripts
00223                     catalog_vars = dict(portal_type=types_by_wf.get(id, []))
00224                     for key in wlist_def.var_matches.keys():
00225                         catalog_vars[key] = wlist_def.var_matches[key]
00226                     for result in catalog.searchResults(**catalog_vars):
00227                         o = result.getObject()
00228                         if o \
00229                            and id in self.getChainFor(o) \
00230                            and wlist_def.getGuard().check(sm, wf, o):
00231                             absurl = o.absolute_url()
00232                             if absurl:
00233                                 objects_by_path[absurl] = (o.modified(), o)
00234 
00235         results = objects_by_path.values()
00236         results.sort()
00237         return tuple([ obj[1] for obj in results ])
00238 

Here is the call graph for this function:

def CMFPlone.WorkflowTool.WorkflowTool.listWFStatesByTitle (   self,
  filter_similar = False 
)
Returns the states of all available workflows, optionally filtering
   out states with matching title and id

Definition at line 292 of file WorkflowTool.py.

00292 
00293     def listWFStatesByTitle(self, filter_similar=False):
00294         """Returns the states of all available workflows, optionally filtering
00295            out states with matching title and id"""
00296         states = []
00297         dup_list = {}
00298         for wf in self.objectValues():
00299             state_folder = getattr(wf, 'states', None)
00300             if state_folder is not None:
00301                 if not filter_similar:
00302                     states.extend(state_folder.objectValues())
00303                 else:
00304                     for state in state_folder.objectValues():
00305                         key = '%s:%s'%(state.id,state.title)
00306                         if not dup_list.has_key(key):
00307                             states.append(state)
00308                         dup_list[key] = 1
00309         return [(s.title, s.getId()) for s in states]

Here is the call graph for this function:

Return the list of workflows

Definition at line 254 of file WorkflowTool.py.

00254 
00255     def listWorkflows(self):
00256         """ Return the list of workflows
00257         """
00258         return self.objectIds()

Here is the call graph for this function:

gathers all the available workflow chains (sequence of workflow ids, ).  

Definition at line 115 of file WorkflowTool.py.

00115 
00116     def workflows_in_use(self):
00117         """ gathers all the available workflow chains (sequence of workflow ids, ).  """
00118         in_use = []
00119 
00120         in_use.append( self._default_chain )
00121 
00122         if self._chains_by_type:
00123             for chain in self._chains_by_type.values():
00124                 in_use.append(chain)
00125 
00126         return tuple(in_use[:])


Member Data Documentation

tuple CMFPlone.WorkflowTool.WorkflowTool.__implements__ = (PloneBaseTool.__implements__, BaseTool.__implements__, ) [static, private]

Definition at line 26 of file WorkflowTool.py.

Definition at line 21 of file WorkflowTool.py.

Definition at line 23 of file WorkflowTool.py.

tuple CMFPlone.WorkflowTool.WorkflowTool.security = ClassSecurityInfo() [static]

Definition at line 22 of file WorkflowTool.py.

string CMFPlone.WorkflowTool.WorkflowTool.toolicon = 'skins/plone_images/workflow_icon.gif' [static]

Definition at line 24 of file WorkflowTool.py.


The documentation for this class was generated from the following file: