[Zope] Lists and external methods
Tony McDonald
tony.mcdonald@ncl.ac.uk
Tue, 4 Jul 2000 15:54:09 +0100
Oleg,
Thanks for that. It's the clearest explanation I've seen as to what
'mapping' does (and I've read the docs a fair bit)
cheers
tone.
At 1:00 pm +0000 4/7/00, Oleg Broytmann wrote:
>On Tue, 4 Jul 2000, Pieter Claerhout wrote:
>> I want the external method to return this in a list, where I can
>>iterate over using the
>> <dtml-in> tag, so that I can reference the different fields in
>>each record with a name.
>>
>> What should the list look like so that I can accomplish this?
>
> dtml-in eats a list of objects or a list of dictionaries.
>
>Example 1.
>
>class Item:
> pass
>
> Your external methods should return:
>
>l = []
>
>item1 = Item()
>item1.date = "21/12/67"
>item1.foo = "bar"
>l.append(item1)
>
>item2 = Item()
>item2.date = "1/1/2000"
>item2.foo = "baz"
>l.append(item2)
>
> ...etc...
>
>return l
>
> In the DTML use the list: <dtml-in thelist><dtml-var
>date></dtml-in thelist>
>
>
>Example 2 (dictionaries).
>
> Your external methods should return:
>
>l = []
>
>item1 = {}
>item1["date"] = "21/12/67"
>item1["foo"] = "bar"
>l.append(item1)
>
>item2 = {}
>item2["date"] = "1/1/2000"
>item2["foo"] = "baz"
>l.append(item2)
>
> ...etc...
>
>return l
>
> In the DTML use the list: <dtml-in thelist mapping><dtml-var
>date></dtml-in thelist>
> ^^^^^^^
> dtml-in needs to be notified these are dicttionaries.
>
>Oleg. (All opinions are mine and not of my employer)
------
Dr Tony McDonald, FMCC, Networked Learning Environments Project
http://nle.ncl.ac.uk/
The Medical School, Newcastle University Tel: +44 191 222 5888
Fingerprint: 3450 876D FA41 B926 D3DD F8C3 F2D0 C3B9 8B38 18A2