[Zope] simplePager
Lee Harr
missive@hotmail.com
Thu, 29 Aug 2002 13:11:01 +0000
I wanted something to split up long lists of items into shorter
lists and make links to the pages (kind of like the page numbers
on a google search)
I saw in the docs that dtml provides this... but I could not get
that to work. It never found the batch-start-index inside of the
previous-batches
Anyhow, i found a script in the zope cookbook, but it was two
pages long and it was way more than i needed. So I made this:
#simplePager
# paramenters:
# seq=None, page=0, size=10
#
req = context.REQUEST
url = req.URL
if req.has_key('start'):
start = getattr(req, 'start')
else:
start = 0
starts = range(1, len(seq)+1, size)
p = 1
for s in starts:
print '<a href="%s?start=%s">%s</a>' % (url, s, p)
p += 1
return printed
It works in conjunction with the dtml sequence stuff as shown
in the help pages... like this:
<dtml-in list_thumbnails size=10 start=start previous>
<a
href="&dtml-absolute_url;&dtml-sequence-query;start=&dtml-previous-sequence-start-number;">Previous
Page</a>
</dtml-in>
where list_thumbnails happens to be another script which just returns a list
of objects (thumbnail images in this case). You might use objectValues there
instead...
_________________________________________________________________
Chat with friends online, try MSN Messenger: http://messenger.msn.com