[ZPT] Has_role in ZPT (and if-then-else) ?
Dieter Maurer
dieter@handshake.de
Sat, 20 Oct 2001 22:05:16 +0200 (CEST)
Tony McDonald writes:
> 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! :)
>
> We were trying to change this code;
> <dtml-if "AUTHENTICATED_USER.has_role('fmcc_man') or
> AUTHENTICATED_USER.has_role('fmcc_admin') or
> AUTHENTICATED_USER.has_role('fmcc') or AUTHENTICATED_USER.has_role('ltsn')
> or AUTHENTICATED_USER.has_role('ltsn_man')">
>
> <select> ... </select>
> </dtml-if>
The direct translation is
<select tal:condition="python: user.has_role('fmcc_man')
or user.has_role('fmcc_admin')
or ....">
...
</select>
> I then made a PythonScript that I thought might work;
> ...
> 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 :(
What does happen instead?
An exception, an infinite loop?
In fact, the Python Script should work.
> My colleague also asked about the
> <dtml-if >
> ....
> <dtml-else>
> ....
> </dtml-if>
>
> construct too, and how this might be done in ZPT. Again, what's the best
> practice on this as well?
ZPT does not have a two way conditional. Thus, the direct
translation is:
<tag condition="expr">
....
</tag>
<tag condition="not: expr">
....
</tag>
Dieter