[Zope] newbie Q. DTML syntax

andres@corrada.com andres@corrada.com
Wed, 31 May 2000 22:00:20 -0400


On Wed, May 31, 2000 at 09:35:58PM +1000, Brad Moulton wrote:
> As a newbie i have tried a few variations on the following
> but the <dtml-if> never returns true
> 
>  <dtml-in "PARENTS[0].objectValues(['customer'])" sort=lname>
>         <dtml-if "(_['sequence-item'].title == AUTHENTICATED_USER)">
>           <tr><td>customer </td><td><dtml-var accno></td>
>     .......and other values from "customers" folder with meta type customer
> </dtml-if>
> </dtml-in>

This gets many, many people (including myself). Zope-defined Web request
variables are usually objects. You are using AUTHENTICATED_USER as if it was
a string, which it is not, thus your dtml-if always fails.

To get what you want, use (Zope Quick Reference v. 0.9):

 AUTHENTICATED_USER.getUserName()

Something that adds to newbies' confusion on this is that if one writes,

<dtml-var AUTHENTICATED_USER>

one gets the very username that one expects but yet the <dtml-if> still fails.
"I can see the freaking name is right!!!! Why are you failing!!???" is the
expurgated version of what I said when I got bit by this one.

The reason that <dtml-var AUTHENTICATED_USER> renders nicely to the same
string that AUTHENTICATED_USER.getUserName() does is that AUTHENTICATED_USER
is an object of type lib/python/AccesControl/User. This object has the
getUserName() method but it also has a "__str__" method that Python allows
to be defined for any class. This "__str__" method is the way that an object
should be represented whenever it is printed. In the case of the User class,
lib/python/AccessControl/User.py defines the method __str__ as:

def __str__(self): return self.getUserName()

------------------------------------------------------
Andres Corrada-Emmanuel   Email: andres@corrada.com
------------------------------------------------------