[ZPT] Has_role in ZPT (and if-then-else) ?

Evan Simpson evan@zope.com
Sun, 21 Oct 2001 14:15:54 -0400


Tony McDonald wrote:

> I was demoing the coolness and scalability of ZPT to a colleague the other
> day and came across a problem I couldn't figure out (fortunately my
> colleague trusts me on these things and knows there'll be a fix! :)


It looks like Dieter has got you past this problem, but I'll add a few 
comments.

> <select tal:condition="python: roles in ['Manager', 'fmcc_admin', 'fmcc',

> 'fmcc_man']"


You can't use "in" to intersect lists.  On the other hand, has_role() 
accepts lists.

> if request.AUTHENTICATED_USER.has_role(therole):
>     return 1
> else:
>     return 0
> 
> Now this *does* work if the AUTHENTICATED_USER has the role I'm looking for
> (ie '1' returned). If AUTHENTICATED_USER does not have that role, this
> PythonScript doesn't even return :(


I presume that you tested this from the browser, using the Test tab. 
Trying to view a Script that is returning a false value (such as 0) in a 
browser causes the browser to continue to show whatever it loaded last. 
  I suspect that if you tested it with <p tal:content="scriptname"></p> 
you would see "0".

Cheers,

Evan @ Zope