[Zope] Newbie Question: Ordering items within a folder based on a property

Dieter Maurer dieter@handshake.de
Fri, 29 Mar 2002 13:38:09 +0100


Ben Chapman writes:
 > ... custom sorting over (potentially) undefined property ....
 > This works, sort of:
 > 
 >   id       sort_value
 > 
 > Folder1 (100)
 > Folder2 (200)
 > Folder3 (300)
 >     FolderA (not defined)
 >     FolderB  (1)
 >     FolderC  (2)
 > 
 > The folders in Folder3 will be sorted as
 > 
 >     FolderB (1)
 >     FolderC (2)
 >     FolderA (300) <--- inherited from Folder3 above.
 > 
 > This is not awful, but I know it's not the right way to do things. How 
 > can I improve it?
You have 2 subproblems:

  *  checking whether an object has a property

     for properties you can use "hasProperty"
     (see Zope Help -> API Reference -> PropertyManager)

     otherwise, you need "aq_base" (see the mailing list archives)

  *  define a custom sort function handling the case that a sort
     value is undefined. It is not clear a priori, how this should
     be handled (see the Python library documentation for the list method
     "sort" for details on custom sort functions).


Dieter