REQUEST variable is not being modified by Zope Python script
Hello. I am calling a Python script called 'incrementCounter' from a DTML Document and passing a variable to it called 'counter'. However, for some reason the value of this variable remains unchanged when control returns to the DTML method. I tested the Python script independently via the management interface and it works fine. The code for both the document and script is listed below. Any help would be greatly appreciated. Thanks. <dtml-call "REQUEST.set('rowLength', 6)"> <dtml-call "REQUEST.set('counter', 0)" > <dtml-in expr="aq_parent.objectValues(['Local File System'])" prefix="fileObject" sort="id" skip_unauthorized> <dtml-if "AUTHENTICATED_USER.has_role(['Local', 'Manager'], this())"> <a href ="/Personal/<dtml-var "getId()">">#<dtml-var "getId()"></a> <dtml-call expr="incrementRowLength(counter)" --> <dtml-var counter> </dtml-if> </dtml-in> increment = 1 counter = int(counter) + int(increment) return counter __________________________________________________ Do you Yahoo!? Yahoo! Mail Plus - Powerful. Affordable. Sign up now. http://mailplus.yahoo.com
You're only changing the value of counter in the scope of the Python script. Your script is returning the new value, but you aren't doing anything with that value. That's why it appears not to be working. But once you get that right, you'll turn up other hassles. :-) I'd advise against using a Python script for this. If all you're doing is counting iterations over a loop, it may be far easier to do this: <dtml-call "REQUEST.set('my_ids', [])"> ... <dtml-if "some_test"> <dtml-call "my_ids.append(getId())"> <a href ="/my_folder/<dtml-var "my_ids[:-1]">> # <dtml-var "my_ids[:-1]"> </a> </dtml-if> ... <dtml-var "len(my_ids)"> item(s) were found. Etc., etc. HTH, Dylan
Try changing
<dtml-call expr="incrementRowLength(counter)" --> <dtml-var counter> to <dtml-call expr="counter= incrementRowLength(counter)"> <dtml-var counter>
Or inside the python script, push the new value of "counter" back into the REQUEST object: DavidH ----- Original Message ----- From: "Asad Habib" <ahabib1357@yahoo.com> To: <zope@zope.org> Sent: Wednesday, February 05, 2003 9:26 AM Subject: [Zope] REQUEST variable is not being modified by Zope Python script
Hello. I am calling a Python script called 'incrementCounter' from a DTML Document and passing a variable to it called 'counter'. However, for some reason the value of this variable remains unchanged when control returns to the DTML method. I tested the Python script independently via the management interface and it works fine. The code for both the document and script is listed below. Any help would be greatly appreciated. Thanks.
<dtml-call "REQUEST.set('rowLength', 6)"> <dtml-call "REQUEST.set('counter', 0)" >
<dtml-in expr="aq_parent.objectValues(['Local File System'])" prefix="fileObject" sort="id" skip_unauthorized>
<dtml-if "AUTHENTICATED_USER.has_role(['Local', 'Manager'], this())"> <a href ="/Personal/<dtml-var "getId()">">#<dtml-var "getId()"></a> <dtml-call expr="incrementRowLength(counter)" --> <dtml-var counter> </dtml-if> </dtml-in>
increment = 1 counter = int(counter) + int(increment) return counter
participants (3)
-
Asad Habib -
David Hassalevris -
Dylan Reinhardt