[Zope] Handling lists in requests?

Alexander Staubo alex@mop.no
Wed, 23 Jun 1999 23:10:01 +0200


You need to tell Zope that adr_list is a list; otherwise, it's assumed
to be a string. Just add ":list" to the form variable name, thusly:

<input type="hidden" name="adr_list:list" value="<!--#var adr_list-->">

Note that if adr_list really is a list (I don't know what your ldif()
function does), you should replace the above with this:

<!--#in adr_list-->
<input type="hidden" name="adr_list:list"
  value="<!--var sequence-item-->">
<!--#/in-->

Why? Because Zope doesn't -- in my experience, I could be wrong -- take
the standard Python syntax for lists as input. Which means that if you
enter an URL roughly like this:

  http://www.foo.com/show_it?adr:list=['a','b','c']

then Zope will assume ['a','b','c'] to be the first item of a 1-length
list. To pass multiple list items, this URL is correct:

  http://www.foo.com/show_it?adr:list=a&adr:list=b&adr:list=c

Zope will join all duplicately-named list arguments into a single list.
Hence the above DTML code, which might yield the following HTML output:

<input type="hidden" name="adr_list:list" value="a">
<input type="hidden" name="adr_list:list" value="b">
<input type="hidden" name="adr_list:list" value="c">

and give you the URL above.

As an aside, let me mention that while this system might seem odd at
first, it's actually very cool, and quite useful, too. For example,
think of a document system where, for every document, editors should
type in one or more authors. Instead of having _one_ editor box where
the user is required to enter author names as a comma-separated list,
you can use Zope lists. The DTML code you might use for this is:

<!--#if authors-->
  <!--#in authors-->
  <input type="text" name="authors:list" size="40"
    value="<!--var sequence-item-->"><br>
  <!--#/in-->
<!--#/if-->
<input type="text" name="authors:list" size="40"><br>
<input type="text" name="authors:list" size="40"><br>
<input type="text" name="authors:list" size="40"><br>

This makes sure that editors always have three available edit fields for
entering three more names. If an editor is editing a document and
suddenly needs to store more than three more names, he can press
"Submit" and continue editing -- he'll be given three more fields. And
so on. A more advanced alternative is to provide a "More fields" button
that will expand the form without saving the data first, much like
Zope's management screens and the "Taller", "Shorter", etc. buttons.

Hmm, isn't this HOWTO fodder, though?

--
Alexander Staubo             http://www.mop.no/~alex/
"What the hell, he thought, you're only young once, and threw
himself out of the window. That would at least keep the element of
surprise on his side."
--Douglas Adams, _The Hitchhiker's Guide to the Galaxy_

>-----Original Message-----
>From: zope-admin@zope.org [mailto:zope-admin@zope.org]On Behalf Of
>Thomas Weiner
>Sent: 23. juni 1999 22:52
>To: zope@zope.org
>Subject: [Zope] Handling lists in requests?
>
>
>Hi,
>
>is there a way to handle lists in requests properly?
>
>For Example:
>
>I have a form getting a list containing a few 'inner' lists from an
>external method 'ldif' (maybe that's already ugly).
>I want to give this list-construct via a request to an action form.
>
><FORM action="show_it" method="post">
><!--#call "REQUEST.set('adr_list',ldif(filename))"-->
><input type = "hidden" name="adr_list" value="<!--#var adr_list-->">
><!--#in adr_list sort-->
>  doing some stuff
><!--#/in adr_list sort-->
>
>The <!--#in adr_list--> action works fine, but when trying the same
><!--#in adr_list--> in 'show_it' I receive an Error:
>
>Error type:  InError
> Error value: Strings are not allowed as input to the in tag.
>
>How should I handle this?
>
>thanks
>Thomas
>--
>fon: ++49 (0)40 42878 3781
>fax: ++49 (0)40 42878 2728
>
>_______________________________________________
>Zope maillist  -  Zope@zope.org
>http://www.zope.org/mailman/listinfo/zope
>
>(For developer-specific issues, use the companion list,
>zope-dev@zope.org - http://www.zope.org/mailman/listinfo/zope-dev )
>