[Zope-CMF] Inadequate expression context in _getViewFor()
Paul Winkler
pw_lists at slinkp.com
Tue Jun 28 21:54:16 EDT 2005
Hi folks,
(this is with CMF 1.4.8)
Today I was puzzling over a pretty simple modification to a TALES expression
in the 'view' action in ... /portal_types/Document/manage_editActionsForm.
It worked fine if I viewed a document at
http://localhost:8080/portal/foo/document_view
but it broke if viewed at
http://localhost:8080/portal/foo .
I simplified the expression until I was able to reproduce the
problem with something as trivial as:
string:${object/absolute_url}/document_view
... which should be more or less equivalent to the default setting:
string:${object_url}/document_view
... but instead, I get "NoneType has no attribute 'absolute_url'".
What the heck?
The traceback pointed me to CMFCore.utils._getViewFor(), which looks up the
view action from the type information - but, weirdly, evaluates
it in a brutally restricted expression context, from
CMFCore.utils.getActionContext:
def getActionContext( self ):
data = { 'object_url' : ''
, 'folder_url' : ''
, 'portal_url' : ''
, 'object' : None
, 'folder' : None
, 'portal' : None
, 'nothing' : None
, 'request' : getattr( self, 'REQUEST', None )
, 'modules' : SecureModuleImporter
, 'member' : None
}
return getEngine().getContext( data )
This is in distinction to the "normal" context it gets when building
the actions to show in the CMF UI. This context comes from
CMFCore.Expression.createExprContext() and has useful bindings for
all of that good stuff.
So we have a slightly schizoid situation in which your View action
TALES expression can do all kinds of cool stuff - EXCEPT when it's
used by _getViewFor(). This seems rather stupid to me.
If this is a deliberate restriction, can anybody explain the rationale?
Or is it, as I suspect, an oversight?
--
Paul Winkler
http://www.slinkp.com
More information about the Zope-CMF
mailing list