[Zope] Sorting catalog reports

Martijn Pieters mj@antraciet.nl
Fri, 17 Sep 1999 13:20:47 +0200


At 06:19 17/09/99 , Chris Fassnacht wrote:
>How do you use the sort attribute in a <dtml-in catalog> statement for a
>Zcatalog search report?
>
>I tried using <dtml-in catalog size=50 start=query_start sort=sortkey>,
>where sortkey is an input value from a Zcatalog search form that provides
>the name of one of the properties to sort on, but I get an AttributeError on
>sortkey.
>
>It works fine if I just enter the property name (e.g., id), and I get a true
>condition when I try <dtml-if "REQUEST.form.has_key('sortkey')"> and I can
>print out the value correctly, so I know the value is making it from the
>search form.
>
>This is probably one of those variable formatting syntax gotchas that I (as
>a new user) am missing.  It'd be nice if I could find a detailed syntax for
>variable expression.  You know, something that tells you when to use _[] or
>_[_[]], and what type of quotes (' or ") to use and when.  Does something
>like this exist, or is it just Python syntax (meaning I should pick up a
>Python book)?

The sort attribute only accepts a the name of the attribute on which to 
sort. It is not an expression, and therefore not dynamic. In your case, 
Zope will try and sort on the 'sortkey' attribute, which does not exist, 
hence the AttributeError.

However, ZCatalog does accept a 'sort-on' attribute. If that variable is 
present in the REQUEST object, or is passed to the searchResults method of 
the catalog, the resultset will be sorted on the index specified in that 
attribute. Note that you can only sort on attributes that are indexed, you 
cannot sort on any of the stored schema data.

Also note that this feature is partly broken in Zope 2.0, but is fixed for 
the next release of Zope. The fix is small: at line 411 of Catalog.py 
(lib/python/Products/ZCatalog), change sort_index.items() into 
sort_index._index.items().


--
Martijn Pieters, Web Developer
| Antraciet http://www.antraciet.nl
| Tel: +31-35-7502100 Fax: +31-35-7502111
| mailto:mj@antraciet.nl http://www.antraciet.nl/~mj
| PGP: http://wwwkeys.nl.pgp.net:11371/pks/lookup?op=get&search=0xA8A32149
------------------------------------------