[albatross-users] al-for firstpage, nextpage, and gotopage
Greg Hamilton
gregh at object-craft.com.au
Tue Mar 9 11:45:08 EST 2004
I revisited the code this morning and, after a little head-scratching,
I pulled out the relevant bits and created a little example app which
you can see in action here:
http://www.object-craft.com.au/cgi-bin/paged-example/app.cgi
or download the source tarball here:
http://www.object-craft.com.au/paged-example.tar.gz
The example app navigates a table off 500 rows of 20 elements of random
numbers. I limit the number of rows per page to 15 which gives you 34
pages to peruse.
The Albatross <al-for> tag uses the Albatross ListIterator class and
already supports pagination. I've written a subclass of ListIterator,
called PagedListIterator, which adds methods for getting and setting
the current page or range of pages.
Note, normally Albatross will automagically create a ListIterator
instance when it encounters an <al-for> loop in a template. To force
Albatross to use a PagedListIterator instead you need to add the
iterator instance to ctx.locals before the template is processed.
In the 'page_enter' method of 'page.py' I create the iterator and add
it to the session vars, something like this:
def page_enter(ctx):
ctx.locals.rows_iter = PagedListIterator()
ctx.add_session_vars('rows_iter', )
In the template 'page.html' the <al-for> loop which uses
'iter="rows_iter"' will use this PagedListIterator instance.
Greg
On 06/03/2004, at 6:16 AM, Michael C. Neel wrote:
> Dave said a while back that Greg(?) had implemented these without
> extending/altering Albatross, and that he could post some code showing
> how it was done. Can we get that code? =p
>
> Mike
> _______________________________________________
> Albatross-users mailing list
> Albatross-users at object-craft.com.au
> https://www.object-craft.com.au/cgi-bin/mailman/listinfo/albatross-
> users
>
More information about the Albatross-users
mailing list