[Zope] Handling lists in requests?

Martijn Pieters mj@antraciet.nl
Thu, 24 Jun 1999 15:32:34 +0200


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