[Zope-dev] Sorting/Reversing dtml-in with URL arguments
Duncan Booth
duncan@rcp.co.uk
Tue, 11 Apr 2000 10:03:45 +0000
> Is it possible to set the sort order and reverse flags on
> a dtml-in tag using URL arguments or REQUEST variables?
Someone asked a while back about specifying the sort key
dynamically. you can find my response in the mailing list archives
(dated 1st Feb 2000, 09:50) as it has a few ideas that may be
useful to you.
> For example, sorting "employees" by "name" in index_html
> would be something like:
>
> index_html?sort
> for
>
> <dtml-in employees>
> ...
> </dtml-in>
>
>
In this case you could try (untested code):
<dtml-let emp=employees>
<dtml-if sort><dtml-call "emp.sort()"></dtml-if>
<dtml-if reverse><dtml-call "emp.reverse()"></dtml-if>
<dtml-in emp>
...
</dtml-in>
</dtml-let>
Provided 'employees' sorts naturally this may be all you need.
Sometimes it may be safer to copy the list before sorting it. I found
this out the hard way once when I sorted what I thought was a
copy of PARENTS, it sorted the original PARENTS list and some
really weird things happened to variable lookup. Most lists may be
copied thus:
<dtml-let emp="employees[:]">...</dtml-let>
If you need to sort on a specific field within employees see my
earlier posting as above.
If the data is in a database use the sql ORDER BY construct to do
the sorting.
--
Duncan Booth duncan@dales.rmplc.co.uk
int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3"
"\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure?
http://dales.rmplc.co.uk/Duncan