[Zope] Handling lists in requests?

Thomas Weiner weiner@tu-harburg.de
Wed, 23 Jun 1999 23:32:23 +0100


Thanks for your reply!

Alexander Staubo schrieb:
> 
> 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-->

I forgot to mention that I tried both, but I loose my index this way.

My original list looks like [['first' 'entry' 'c'], ['another' 'entry'
'c'] , ...]
In the original list I can do an index over the entire list

<!--#in adr_list-->
 <!--#var "_['sequence-item'][0]"--> -->'first' 'another' ...
 <!--#var "_['sequence-item'][1]"--> -->'entry' 'entry' ...
<!--#!in adr_list-->

In ../show_it the same shows for [0]'f' 'a' ...for [1] 'e' 'n'...

> 
> 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

Okay .. I have to see how to split my original list. Somehow I feel it's
better to rebuild the python function and to put this stuff into a kind
of class. This seems to be easier.

> 
> 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.

That's rigth .. this is really cool  .. like a lot of other Zope-things
:)

-- 
fon: ++49 (0)40 42878 3781
fax: ++49 (0)40 42878 2728