[ZPT] Re: batching and sorting in one go

Casey Duncan casey@zope.com
Mon, 1 Jul 2002 09:14:44 -0400


On Thursday 27 June 2002 03:25 pm, Michal Kurowski wrote:
> Casey Duncan [casey@zope.com] wrote:
> > The problem is that the batch object has no sort method. So it throws
> > that attribute error when you call: out =3D batch.sort(...)
> >=20
> > You need to sort the results before you batch it. Since you are using=
 a
> > ZSQL method, it probably makes sense to add a variable "ORDER BY" cla=
use
> > to it, passing the name of the column to sort on as an argument to th=
e
> > ZSQL method.
> >=20
> > Then the database will do the sorting for you which is usually
> > desireable.
> >=20
> > hth,
> >=20
> > -Casey
>=20
>=20
> OK, your right but I'm still having problems...
>=20
> How would I test presence of "sorted" and non-sorted sql results in a
> template ?=20

Do you have a default sort order? Let's say by default you sort descendin=
g by=20
date. You use a tal:define that looks in request for a sort order or prov=
ides=20
a default:

<div tal:define=3D"variable request/sort_on | string:date;=20
     mode request/sort_order | string:desc;
     results python:here.pass_sorted(variable=3Dvariable, mode=3Dmode)">
   ...
</div>

>=20
> I've got that:
>=20
> <a tal:attributes=3D"href python: here.pass_sorted(variable=3D'status',=
=20
mode=3D'asc')">
>=20
> where pass_sorted is anothr ZSQL method that takes additional
> parameters.
>=20
> Is there a simple way to re-render my template after testing "results" =
?

No re-rendering is needed. Except when the user changes the sort order wh=
ich=20
will generate a whole new request anyway and re-execute your template cod=
e.

>=20
> --
> Michal Kurowski
> <michal@genesilico.pl>

hth,

Casey