[Zope] Sorting a custom-built list with dtml-in
Tino Wildenhain
tino at wildenhain.de
Fri Aug 15 19:33:55 EDT 2003
Hi Robert,
Robert Jean wrote:
> Hello,
>
> I have a DTML method that iterates over a list built
> by a Python script with the <dtml-in> tag. I want to
> be able to sort the list (with the attribute
> sort=sortColumn in the dtml-in tag). I have a few
> questions on this topic:
>
> 1) I assume that the dtml-in tag does not know how to
> sort a list of dictionaries having the same keys. It
> only knows how to sort Python class instances. Is it
> correct?
>
> 2) If I have to store Python class instances in my
> list, what feature must the class have? Does it have
> to inherit from Acquisition.Implicit, and / or
> Record.Record?
>
> 3) Do I miss something else on this topic?
>
> Thanks for your help,
> Robert
From what I know, DTML in happyly sorts on lists
of dictionaries.
If you are using a python script to generate the
list, you can easy do the sorting there also.
See
http://zope.org/Documentation/Books/ZopeBook/2_6Edition/AppendixB.stx/view
module "sequence"
You dont have to import it into python script, its already
available. Just use it like this:
return
sequence.sort(yoursequence,[('key','cmp','asc'),('otherkey','cmp','asc')])
see the documentation for hints on sorting. There are a lot of
options.
This also helps when you finally skip DTML and use ZPT.
Regards
Tino
More information about the Zope
mailing list