[ZDP] BackTalk to Document The Zope Book (2.5 Edition)/Advanced Page Templates

webmaster@zope.org webmaster@zope.org
Fri, 04 Oct 2002 12:22:16 -0400


A comment to the paragraph below was recently added via http://www.zope.org/Documentation/Books/ZopeBook/current/AdvZPT.stx#4-20

---------------

        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>

          % Anonymous User - Sep. 25, 2002 6:02 pm:
           This example is copied from AppendixB Module sequence
           http://www.zope.org/Documentation/Books/ZopeBook/current/AppendixB.stx
           Note that in "sequence.sort(seq, sort)" the "sort" argument is a *sequence of tuples*.
           While you save time copying, i waste time grokking.

          % Anonymous User - Oct. 3, 2002 6:37 pm:
           Ditto the above comment. Please explain what the heck you're doing. I'm lost.

          % Anonymous User - Oct. 4, 2002 12:22 pm:
           We're all lost.  Get used to it. ;-)