home contents changes options help subscribe edit (external edit)

A quick reference for anything relating to sorting in Zope.

http://zopewiki.org/ZopeWiki/searchwiki?expr=sort
all matches for "sort" in this wiki
[ZB Searching and Categorizing Content]?
sorting catalog search results, see Advanced Catalog Topics

sequence.sort

sequence.sort is a sorting utility, useful in page templates, dtml, python scripts etc. See http://www.zope.org/Control_Panel/Products/OFSP/Help/sequence.py . [ZB Advanced Page Templates]? says:

  Another useful feature that isn't supplied by tal:repeat is sorting. If you want to 
  sort a list you can either write your own sorting script (which is quite easy in Python) 
  or you can use the sequence.sort utility function. Here's an example of how to sort a 
  list of objects by title, and then by modification date:

          <table tal:define="objects here/objectValues;
                             sort_on python:(('title', 'nocase', 'asc'),
                                             ('bobobase_modification_time', 'cmp', 'desc'));
                             sorted_objects python:sequence.sort(objects, sort_on)">
            <tr tal:repeat="item sorted_objects">
              <td tal:content="item/title">title</td>
              <td tal:content="item/bobobase_modification_time">
                modification date</td>  
            </tr>
          </table>

  This example tries to make things clearer by defining the sort arguments outside the 
  sort function. The sequence.sort function takes a sequence and a description of how to 
  sort it. In this example the description of how to sort the sequence is defined in the 
  sort_on variable. See Appendix B, API Reference for more information on the powerful 
  sequence.sort function.

Here's [ZB Appendix B: API Reference]?. Another example (sorting wiki page brains):

 pages=pages
 pagesbysize="_.sequence.sort(pages,(('size','cmp','desc'),))"
 pagesbylastedit="_.sequence.sort(pages,(('lastEditTime','cmp','desc'),))"



subject:
  ( 23 subscribers )