commit 8e730e4659af98922c4bfce0639f169d0dbe19dc
parent 9787eb79b4064663dfa63327db276f5c12e31728
Author: Dan Callaghan <djc@djc.id.au>
Date: Sat, 7 Jun 2008 23:48:43 +1000
pagination
committer: Dan Callaghan <djc@djc.id.au>
--HG--
extra : convert_revision : 7257e3cec5dc5414e727c34b40f1fb2297b96be5
Diffstat:
2 files changed, 18 insertions(+), 6 deletions(-)
diff --git a/app.py b/app.py
@@ -35,7 +35,8 @@ class BlogApplication(RegexApplication):
rendered = template_loader.load('multiple.xml').generate(
title=None,
all_categories=self.entries.categories(),
- entries=self.entries
+ entries=self.entries,
+ offset=int(self.request.args.get('offset', 0))
).render('xhtml')
return HttpResponse(rendered, [('Content-Type', 'text/html')], 200)
@@ -60,7 +61,8 @@ class BlogApplication(RegexApplication):
rendered = template_loader.load('multiple.xml').generate(
title=u'%s category' % category,
all_categories=self.entries.categories(),
- entries=entries
+ entries=entries,
+ offset=int(self.request.args.get('offset', 0))
).render('xhtml')
return HttpResponse(rendered, [('Content-Type', 'text/html')], 200)
@@ -73,7 +75,8 @@ class BlogApplication(RegexApplication):
rendered = template_loader.load('multiple.xml').generate(
title=u'“%s” tag' % tag,
all_categories=self.entries.categories(),
- entries=entries
+ entries=entries,
+ offset=int(self.request.args.get('offset', 0))
).render('xhtml')
return HttpResponse(rendered, [('Content-Type', 'text/html')], 200)
diff --git a/templates/multiple.xml b/templates/multiple.xml
@@ -13,9 +13,18 @@
<h2 class="archives" py:if="title">Archive for the ${title}</h2>
-<py:for each="entry in sorted(entries, key=lambda e: e.publication_date, reverse=True)[:20]">
- ${show_entry(entry, show_comments=False)}
-</py:for>
+<py:with vars="sorted_entries = sorted(entries, key=lambda e: e.publication_date, reverse=True);
+ show_prev = bool(offset);
+ show_next = len(sorted_entries) > offset + 20">
+ <py:for each="entry in sorted_entries[offset:offset + 20]">
+ ${show_entry(entry, show_comments=False)}
+ </py:for>
+ <p py:if="show_prev or show_next">
+ <a py:if="show_prev" href="?offset=${max(0, offset - 20)}">« previous page</a>
+ <py:if test="show_prev and show_next">—</py:if>
+ <a py:if="show_next" href="?offset=${offset + 20}">next page »</a>
+ </p>
+</py:with>
</body>
</html>