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

Tony McDonald tony.mcdonald@ncl.ac.uk
Sun, 21 Oct 2001 19:41:02 +0100


On 21/10/01 7:15 pm, "Evan Simpson" <evan@zope.com> wrote:

> 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.
> 

Ah, *that* is very useful to know...

>> 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".
> 

Yes I did, and it was returning a false value. Yet another snippet to file
away for later use.

Many thanks for this Evan, you've saved me quite a lot of time recently! :)

Cheers,
Tone.
-- 
Dr Tony McDonald,  Assistant Director, FMCC, http://www.fmcc.org.uk/
The Medical School, Newcastle University Tel: +44 191 243 6140
A Zope list for UK HE/FE  http://www.fmcc.org.uk/mailman/listinfo/zope