[Zope] sort problem

Oleg Broytmann Oleg Broytmann <phd@phd.pp.ru>
Fri, 19 Apr 2002 18:03:03 +0400


On Fri, Apr 19, 2002 at 03:49:19PM +0200, Klaus Boehm wrote:
> I have an object "Internet_Ticket" and every Instance from the object
> has a id.
> 
> <dtml-in "object.Values(['Internet_Ticket']) " sort=id>
> 
> but if i show the objects there is a strange sequence.
> 
> 1 10 100 101 102 103 .... 109 11 110 .....
> 
> It seems its a binary sequence.

   No, it is lexicography (string) order. To sort, you want convert IDs
from strings to ints. Write a simple Python Script:

# Python Script; id: cmp_int; params: id1, id2
return cmp(int(id1), int(id2))

   and sort by the function:

<dtml-in "object.Values(['Internet_Ticket'])" sort="id/cmp_int">

Oleg.
-- 
     Oleg Broytmann            http://phd.pp.ru/            phd@phd.pp.ru
           Programmers don't die, they just GOSUB without RETURN.