[ZPT] sorting

Lynn Walton waltonl@franklin.edu
Wed, 23 Jan 2002 12:14:23 -0600

I'm pasting in the content of one of my previous questions to the list, and Evan's answer:

> I'm trying to access the DocumentTemplate/sequence/SortEx module from a
> ZPT and I've tried about every variation I can think of: and can't get
> it.

It doesn't have the security declarations necessary to import it using
'modules', but 'sequence' is directly available as a Python builtin:

<p tal:repeat="ob python:sequence.sort(container.objectValues(), (('meta_type',),))"
   tal:content="ob/id | nothing">Object</p>


> hey guys, I'm trying to perform batching (got that part already!) and
> sorting (no clue yet) using zpt
> I usually do the following:
> myList=context.objectValues()
> myList.sort(lambda a,b: cmp(a.getId(), b.getId()))
> b=Batch(myList, size, start, orphan=0)
> but I was wondering if Page Templates, ZTUtils or whatever brings a better
> or easier way to perform sorting.
> you know.. something as <dtml-in myList sort=someKey mapping> which is
> pretty straight forward than using lambda's or custom compare functions for
> sorting tuples, dicts, etc
> I've been searching the list archive and didn't found much about it. The
> zpt_examples.zexp have compilation errors and other kind of errors on some
> of its examples, and I couldn't find anything about sorting at the source
> code of ZTUtils... so, here I am waiting for some usefull feedback :)
> Alex