[ZPT] passing a list argument from ZPT to python ...

erik vogan lynx at wimpy.micromammoth.com
Thu Feb 17 13:10:10 EST 2005


Hello,

    i'm new to python and zope, so if anyone could help me with this i
would appreciate it.  what i am trying to do seems like it should be
fairly common, so i'm certain that i am doing something brain-dead,
but i just can't seem to figure it out.

    basically, i am trying to present the user with a confirmation page.
i have a python procedure which processes some form input, then produces
a python list (say, ['24', '28']).  that python proceedure passes the
list to a ZPT page, which iterates through the list, pulling records
from a database (using tal:repeat) and displaying them, then asking the
viewer if they are certain they want to take the action.  up to this
point everything works.

    if they press the "Yes" button, then the ZPT page is supposed to
pass the same (python) list (again, ['24', '28']) to another python
procedure that takes the desired action.  however, instead of passing
a list the ZPT page is passing a string (like: "['24', '28']").  if i
explicitly request that the ZPT page pass a list, i get a list which
encapsulates the string (like: [ "['24', '28']" ] ).

    skeleton code appears below.  can anyone help me by spotting my
error ?  many thanks for any help.


---- list.zpt ---- argument list is called "list"

<html>
<body>
<div tal:repeat="loopvar options/list">
   ... do something with loopvar ...
</div>
<form action="listAction.py" method="post">
  <input type=hidden name="listpass" value=""
         tal:attributes="value options/list" />
  <p align=center> <a href="cancel.html"> <img src="images/cancel.png"></a>
  <input type="image" src="images/confirm.png" alt="OKAY" name="confirm">
  </p>
</form>
</body>
</html>

---- listAction.py ---- argument list is now called "listpass"

## Script (Python) "listAction.py"
##bind container=container
##bind context=context
##bind namespace=
##bind script=script
##bind subpath=traverse_subpath
##parameters=listpass
##title= take action confirmed by user
##
# process the action list
for i in range(0,len(listpass)):
  print "listpass[%i] = %s" % (i, listpass[i])
return printed

---- output of listAction.py ---- from memory; may be slightly inaccurate

listpass[1] = [
listpass[2] = '
listpass[3] = 2
listpass[4] = 4
listpass[5] = '
listpass[6] = ,
listpass[7] =
listpass[8] = '
listpass[9] = 2
listpass[10] = 8
listpass[11] = '
listpass[12] = ]


                        erik 'evil veteran programmer' vogan

~ Of all the races in all of the Galaxy who could have come and said a
big hello to the planet Earth, he thought, didn't it just have to be the
Vogons.                                             - HHGttG


More information about the ZPT mailing list