[ZPT] batching and sorting in one go
Casey Duncan
casey@zope.com
27 Jun 2002 14:39:50 -0400
The problem is that the batch object has no sort method. So it throws
that attribute error when you call: out = batch.sort(...)
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" clause
to it, passing the name of the column to sort on as an argument to the
ZSQL method.
Then the database will do the sorting for you which is usually
desireable.
hth,
-Casey
On Thu, 2002-06-27 at 14:12, Michal Kurowski wrote:
> Hi,
>
> I'm rather a newcomer to Zope and I'm afraid I try to do something I'm
> not quite up to.
>
> There's a lot of nice guides on sorting and batching but I'm still I'm
> having a lot of trouble to put the pieces together.
>
> What I've got:
>
> A rather simple ZSQL method which is supposed to be displayed in the
> table. There are links on that page to sort results based on some
> criteria and there're batching links.
>
> I decided to do this like this: Do everything in a Py script which has
> parameters both from the ZSQl method and from those sorting links.
> My script is a stolen one from the zopelabs example by cduncan.
>
> I try to modify it to accept additional parameters to enable sorting
> like this:
>
> <td width="15%" align="right"><a tal:attributes="href python:
> here.adv_sort(results,arg='born',mode='up')" href="up"><span
> tal:replace="structure root/meta/images/up">up</span></a></td>
>
> <td width="15%" align="right"><a tal:attributes="href python:
> here.adv_sort(results,arg=born,mode='down')" href="down"><span
> tal:replace="structure root/meta/images/down">down</span></a></td>
>
> etc.
>
> and in the script:
>
> batch = Batch(results, size, start, 0, orphan, overlap)
>
> if arg is not None and mode is not None:
> if mode == 'up':
> out = batch.sort(arg, 'asc')
> elif mode == 'down':
> out = batch.sort(arg, 'desc')
> else:
> out = batch
>
> Something is wrong in here - I've errors like
>
> Error Type: TALESError
> Error Value: exceptions.AttributeError on sort in "", at line 46, column 34
>
> Could you please explain it me ?
>
> --
> Michal Kurowski
> <michal@genesilico.pl>
>
>
> _______________________________________________
> ZPT mailing list
> ZPT@zope.org
> http://lists.zope.org/mailman/listinfo/zpt