[ZPT] sequence.sort .. tricky example

Jean Jordaan jean@upfrontsystems.co.za
Wed, 14 Aug 2002 17:48:02 +0200


Hi all

Perhaps it's just me, but I thought this example (from
http://www.zope.org/Documentation/Books/ZopeBook/2_6Edition/AppendixB.stx#4-140
) might bite the unwary (read: me):

<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>

If you don't have two keys to sort on, the definition of 'sort_on' becomes
either of these:

   sort_on python:(('title', 'nocase', 'asc'), );
   sort_on python:[('title', 'nocase', 'asc')];

but not these:

   sort_on python:(('title', 'nocase', 'asc'));
   sort_on python:('title', 'nocase', 'asc');

IMHO, that might be a FAQ-in-waiting that might as well be addressed
where the example is given ..

-- 
Jean Jordaan
Upfront Systems                         http://www.upfrontsystems.co.za