make page numbers 1-based so they line up with the page numbers listed in the navigation
authorTed Mielczarek <ted.mielczarek@gmail.com>
Mon, 21 Jul 2008 15:56:59 -0400
changeset 32 fa0ce7b3ce1a7f6a7a7caccb8a8e011daa4776bb
parent 31 c8b39f9d6c14b74fd9b82b0e757ab1ace7b8bc71
child 33 7fbe834c1b97d7f1bf22ce358fad80a472c7808b
push id9
push usertmielczarek@mozilla.com
push dateMon, 21 Jul 2008 19:58:10 +0000
make page numbers 1-based so they line up with the page numbers listed in the navigation
pushlog-feed.py
--- a/pushlog-feed.py
+++ b/pushlog-feed.py
@@ -51,34 +51,34 @@ def pushlogSetup(web, req):
     repopath = os.path.dirname(web.repo.path)
     reponame = os.path.basename(repopath)
     if reponame == '.hg':
         reponame = os.path.basename(os.path.dirname(repopath))
     pushdb = os.path.join(web.repo.path, "pushlog2.db")
     conn = sqlite.connect(pushdb)
 
     if 'node' in req.form:
-        start = int(req.form['node'][0])
+        page = int(req.form['node'][0])
     else:
-        start = 0
+        page = 1
 
-    e = getpushlogentries(conn, start * PUSHES_PER_PAGE, 10)
+    e = getpushlogentries(conn, (page - 1) * PUSHES_PER_PAGE, 10)
     total = gettotalpushlogentries(conn)
     proto = req.env.get('wsgi.url_scheme')
     if proto == 'https':
         proto = 'https'
         default_port = "443"
     else:
         proto = 'http'
         default_port = "80"
     port = req.env["SERVER_PORT"]
     port = port != default_port and (":" + port) or ""
 
     urlbase = '%s://%s%s' % (proto, req.env['SERVER_NAME'], port)
-    return (e, urlbase, reponame, total, start)
+    return (e, urlbase, reponame, total, page)
     
 def pushlogFeed(web, req):
     (e, urlbase, reponame, total, page) = pushlogSetup(web, req)
 
     resp = ["""<?xml version="1.0" encoding="UTF-8"?>
 <feed xmlns="http://www.w3.org/2005/Atom">
  <id>%(urlbase)s%(url)spushlog</id>
  <link rel="self" href="%(urlbase)s%(url)spushlog" />
@@ -133,27 +133,27 @@ def pushlogHTML(web, req, tmpl):
         branch = ctx.branch()
         if branch != 'default' and repo.branchtags().get(branch) != ctx.node():
             branches.append({"name": branch})
         return branches
 
     def changenav():
         nav = []
         numpages = int(ceil(total / float(PUSHES_PER_PAGE)))
-        start = max(0, page - PUSHES_PER_PAGE/2)
-        end = min(numpages, page + PUSHES_PER_PAGE/2)
-        if page != 0:
-            nav.append({'page': 0, 'label': "First"})
+        start = max(1, page - PUSHES_PER_PAGE/2)
+        end = min(numpages + 1, page + PUSHES_PER_PAGE/2)
+        if page != 1:
+            nav.append({'page': 1, 'label': "First"})
             nav.append({'page': page - 1, 'label': "Prev"})
         for i in range(start, end):
-            nav.append({'page': i, 'label': str(i+1)})
+            nav.append({'page': i, 'label': str(i)})
         
-        if page != numpages - 1:
+        if page != numpages:
             nav.append({'page': page + 1, 'label': "Next"})
-            nav.append({'page': numpages - 1, 'label': "Last"})
+            nav.append({'page': numpages, 'label': "Last"})
         return nav
     
     def localdate(ts):
         t = time.localtime(ts)
         offset = time.timezone
         if t[8] == 1:
             offset = time.altzone
         return (ts, offset)