[Zope] TALES Confusion

Casey Duncan casey at zope.com
Mon Feb 9 13:33:10 EST 2004


On Mon, 09 Feb 2004 17:45:17 +0000
Philip Kilner <phil at xfr.co.uk> wrote:

> Hi List,
> 
> I'm obviously missing something fundamental about how TALES
> expressions work - I can't get the simplest thing that works fine in a
> ZPT to work in a Formulator TALES expression.
> 
> Example: -
> 
> - In my ZPT, I'm using "user/getUserName", which works perfectly.
> 
> - I'd now like to migrate this functionality to a Formulator form, and
> 
> it seems to me that the above is a path expression, so 
> "path:user/getUserName" or - since the docs a say that a path
> expression is the default - the original "user/getUserName" (Which I
> had understood /was/ a TALES expression) should work. No such luck - I
> just get variations on the theme of "Key Error" and "global not
> defined".
> 
> I have now descended into that special hell of trying all the 
> combinations and permutations, and have run out of options. Could some
> 
> kind soul give me a pointer - this just isn't possible by trial and 
> error, and I've now run out of resources...

Probably Formulator does not supply the global "user" like ZPT does. You
might have to resort to:

python:modules['AccessControl'].getSecurityManager().getUser().getUserN
ame()

But that assumes that Formulator supplies "module" which it may not. I
would just
create a python script called "getUserName" which contains the code:

from AccessControl import getSecurityManager
return getSecurityManager().getUser().getUserName()

Then use: here/getUserName as the path expression (assuming Formulator
uses "here"). As you can see Products are free to create whatever
variable bindings they like for their TALES expressions.

hth,

-Casey



More information about the Zope mailing list