[Zope] dtml-in sort by generic function

Dieter Maurer dieter@handshake.de
Tue, 13 Mar 2001 23:13:58 +0100 (CET)


Oleg Broytmann writes:
 > ... controling sorting in "dtml-in" ...
 > ....
 > but a colleague of mine, Dennis Otkidach suggested more general approach -
 > to make a patch that will allow to pass a generic function to sort(),
 > something like
 >    <dtml-in seq sort=surname sort_func=foobar> where sort_func points to a
 > Python function (like locale.strcoll), or Python Script function, or such.
 > 
 >    Any opinion? I see a minor problem here - if I want just locale-aware
 > sort, I would write
 >    <dtml-in seq sort=surname sort_func=_.locale.strcoll>,
A very good idea!

However, you should note:

  *  "dtml-in" does not sort single values, but tuples
     ( sort_values, client), where "sort_values" is
     either a single value or a list of values and
     "client" is the current element.

     Your sort function must handle this case

  *  "dtml-in" supports multiple sort keys.
     I would expect to have a comparison function for
     each sort key, with the global comparison function
     a composition of that for the sort keys.

     Thus, you can combine a locale sensitive sort with
     (e.g.) a date sort.


Dieter