RE: [Zope] Handling lists in requests?
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 )
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:
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
At 00:32 24/06/99 , Thomas Weiner wrote:
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'...
Hmmm... that's because more complex data structures don't let themselves be marshalled that easily. There is no direct support for lists of lists for example. What you could do, is handle the marshalling of the sublists yourself, like so: <!--#in adr_list--> <input type="hidden" name="joined_adr_list:list" value="<!--#var "_.string.join(sequence-item, <SEPARATOR>)"-->"> <!--#/in--> and unpack the sublists in show_it like so: <!--#call "REQUEST.set(adr_list, [])"--> <!--#in joined_adr_list--> <!--#call "adr_list[sequence-index] = _.string.split(sequence-item, <SEPARATOR>)"--> <!--#/in--> where <SEPARATOR> is a string containing a character or sequence of characters that will not appear in your data. What the join and split methods do, is convert your sublists to strings, and in show_it convert the strings back to lists. -- Martijn Pieters, Web Developer | Antraciet http://www.antraciet.nl | Tel: +31-35-7502100 Fax: +31-35-7502111 | mailto:mj@antraciet.nl http://www.antraciet.nl/~mj | PGP: http://wwwkeys.nl.pgp.net:11371/pks/lookup?op=get&search=0xA8A32149 ------------------------------------------
participants (3)
-
Alexander Staubo -
Martijn Pieters -
Thomas Weiner