[Zope-CMF] Re: getActionById replacement

yuppie y.2005- at wcm-solutions.de
Fri Oct 21 10:31:06 EDT 2005


Hi Chris!


Chris Withers wrote:
>>> 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.

Seems I successfully tried to forget the ugly things it does;) You are 
right. It's always a good idea to look at the code.

>> getActionObject(action_path) is the method you are looking for.
>>
>> ti.getActionObject('object/view') should work for you.
> 
> Well, that returns an action object :-(

Oops! Should have had a better look at the Plone code. I thought you 
need the 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 :-(

Well. getActionByID did make sense before type actions became normal 
actions in CMF 1.4. Since than getActionByID is an ugly backwards 
compatibility hack that tries to guess the called method from an 
expression string that defines a context dependent URL.

getActionByID has irresolvable bugs because it tries to do something 
impossible. It only does what you expect as long as you make sure your 
action expressions are parsable by getActionByID.

I doubt your use case is a legit use case. If you just want the 
deprecation warnings "to STFU" you have to reimplement getActionByID. If 
you want to do things right, you don't need a replacement for getActionByID.

What are the "plenty more apparently legit uses of getActionByID"?


Cheers,

	Yuppie




More information about the Zope-CMF mailing list