[Zope-CMF] Re: getActionById replacement

Chris Withers chris at simplistix.co.uk
Fri Oct 21 11:02:47 EDT 2005


yuppie wrote:
> 
> 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.

That may be, but how would you code what's being done above?
It seems like a moderately legitimate use to me, but I may be missing 
something :-S

> getActionByID has irresolvable bugs because it tries to do something 
> impossible. 

And what is that?

> It only does what you expect as long as you make sure your 
> action expressions are parsable by getActionByID.

What does that mean, in simple terms?

> I doubt your use case is a legit use case. 

As I said before, how would you code the above?

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

Well, legit may be the wrong word, but "I can't thing how to implement 
this other than by having a getActionById" :-(
Anyway, here they are:

- in CMFPlone/PloneTool.py, getActionById is used to return only the 
last segment of the URL for the action. Surely getActionInfo()['url'] 
returns the whole url?

Mindyou, what would you expect:
type_info.getActionInfo('object/view')['url']
...to return? The complete url, or just the thing to be appended on the 
end of the object's url?

If it's the latter, I think it's a grossly misnamed key :-(
Why isn't it called url_segment?

cheers,

Chris

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


More information about the Zope-CMF mailing list