[Zope-CMF] Re: getActionById replacement

Chris Withers chris at simplistix.co.uk
Fri Oct 21 07:04:53 EDT 2005


yuppie wrote:
> listActionInfos() returns a tuple of ActionInfo objects, getActionInfo() 
> the first ActionInfo that passes the checks. Note that ActionInfo is a 
> dict, not the persistent Action object you need.

Ah, okay, dunno how I ended up on that trail...

>>> 'action paths' are the unique identifiers of Actions. 'view' doesn't 
>>> identify an Action because there might be 'object/view' and 
>>> 'foo/view'. 'action paths' have the format <category>/<id>.
>>
>> Ah, okay, so what does getActionById('view'), in its deprecated form, 
>> actually do?
> 
> It returns the first 'view' Action it finds.

I dug deeper, not quite true ;-)
It gets the 'view' action object and evaluates it's action attribute in 
a newly created expression context, strips off the leading slash if 
there is one and then returns the result.

> getActionObject(action_path) is the method you are looking for.
> 
> ti.getActionObject('object/view') should work for you.

Well, that returns an action object :-(

Now in plone, they do:

view=typeInfo.getActionById('view')
typeObj._setPropValue('immediate_view',view)

The best I've managed to come up with to replace that is:

from Products.CMFCore.utils import getActionContext
for possible in ('object/view','folder/view'):
     action = typeInfo.getActionObject(possible)
     if action is not None:
         break
else:
     raise RuntimeError('No sensible view found for'+repr(typeInfo))
view=action.action(getActionContext(typeInfo)).strip().lstrip('/')
typeObj._setPropValue('immediate_view',view)

...which seems pretty heavyweight to me :-S

There's also plenty more apprently legit uses of getActionByID in the 
code, which has left me wondering exactly why this method was 
deprecated, given that the suggested replacements don't really seem to 
cut it :-(

cheers,

Chris

-- 
Simplistix - Content Management, Zope & Python Consulting
            - http://www.simplistix.co.uk


More information about the Zope-CMF mailing list