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> I have previously modified an add_instance method to store AUTHENTICATED_USER as the "title" viewing the folder shows this to be so. If I display these values they appear the same. I just do not know the correct syntax inside <dtml-if> brad
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>
I have previously modified an add_instance method to store AUTHENTICATED_USER as the "title" viewing the folder shows this to be so. If I display these values they appear the same. I just do not know the correct syntax inside <dtml-if>
You actually have the syntax correct, you're just comparing apples to oranges. AUTHENTICATED_USER is an object, that when called just happens to return a string. Your if statement above is comparing the string attribute title to the object AUTHENTICATED_USER, which is why it's always returning false. The correct comparison above would be: <dtml-if "(_['sequence-item'].title == AUTHENTICATED_USER.getUserName())"> The getUserName function of the AUTHENTICATED_USER object returns a string containing the username. -- Nick Garcia | ngarcia@codeit.com CodeIt Computing | http://codeit.com
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 ------------------------------------------------------
tried --------------- <dtml-in "PARENTS[0].objectValues(['job'])" sort=cust> <dtml-if "_['sequence-item'].title == AUTHENTICATED_USER.getUserName()"> <TR> <TD rowspan="2" width="16%"><dtml-var j_number> --------------------------- and variations still no joy..... is the best way to mast the dtml syntax by learning python I am afraid I feel lost reading the DTML reference can't when to use what syntax feel like a moron can't even do a simple if statement help appreciated brad
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 ------------------------------------------------------
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
On Fri, Jun 02, 2000 at 11:27:55PM +1000, Brad Moulton wrote:
tried --------------- <dtml-in "PARENTS[0].objectValues(['job'])" sort=cust> <dtml-if "_['sequence-item'].title == AUTHENTICATED_USER.getUserName()"> <TR> <TD rowspan="2" width="16%"><dtml-var j_number> --------------------------- and variations still no joy.....
Your problem is probably not related to AUTHENTICATED_USER.getUserName() but something else. The following works for me: <dtml-in "'nobody', 'webmaster'"> <dtml-var sequence-item><br> <dtml-var AUTHENTICATED_USER><br> <dtml-if "_['sequence-item'] == AUTHENTICATED_USER.getUserName()"> Success!<br> <dtml-else> Failure!<br> </dtml-if> <p> </dtml-in> Test sequence-item.title to make sure it is returning what you want. ------------------------------------------------------ Andres Corrada-Emmanuel Email: andres@corrada.com ------------------------------------------------------
participants (3)
-
andres@corrada.com -
Brad Moulton -
Nick Garcia