Permalink
Browse files

cursor for the archive handler

  • Loading branch information...
Benjamin Golub
Benjamin Golub committed Aug 27, 2010
1 parent 30dd00a commit 4cc69bab5940fc29b0ed2bb39a4b2441ccbeaa2f
Showing with 14 additions and 3 deletions.
  1. +11 −3 blog.py
  2. +3 −0 templates/archive.html
View
14 blog.py
@@ -179,9 +179,17 @@ def get(self):
class ArchiveHandler(BaseHandler):
@tornado.web.removeslash
def get(self):
- entries = db.Query(Entry).filter("hidden =", False).order("-published")
- self.recent_entries = entries[:5]
- self.render("archive.html", entries=entries)
+ q = db.Query(Entry).filter("hidden =", False).order("-published")
+ cursor = self.get_argument("cursor", None)
+ if cursor:
+ try:
+ q.with_cursor(cursor)
+ except (db.BadRequestError, db.BadValueError):
+ cursor = None
+ entries = q.fetch(limit=10)
+ if not cursor:
+ self.recent_entries = entries[:5]
+ self.render("archive.html", entries=entries, cursor=q.cursor())
class ComposeHandler(BaseHandler):
View
@@ -16,4 +16,7 @@ <h2>{{ _("Archive") }}</h2>
</li>
{% end %}
</ul>
+ {% if entries and cursor %}
+ {{ modules.Navigation(cursor) }}
+ {% end %}
{% end %}

0 comments on commit 4cc69ba

Please sign in to comment.