[Zope] Lists and external methods
Tino Wildenhain
tino@wildenhain.de
Thu, 06 Jul 2000 00:47:46 +0200
Hi,
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.
I usually use the following helper-class:
class generic_datarecord:
" This class provides an overall mapping of value pairs "
def __init__(self,**data):
self.data=data
def __len__(self):
return(len(self.data.keys()))
def __getitem__(self,key):
return(self.data[key])
def __getattr__(self,key):
return self.__getitem__(key)
def keys(self):
return(self.data.keys())
def values(self):
return(self.data.values())
if you use generic_datarecord(column1=value1,coulumn2=value2) for each
row,
you can alterate over a list of such datarecord_objects with
<dtml-in> using <dtml-var column1> and <dtml-var column2>
HTH
Tino Wildenhain
PS: __len__() is optional, but for easy use in all circumstances
(e.g. <dtml-in> over a single datarecord)