changeset 90:d29100da202a

fix ?posts=5
author Jeff Hammel <jhammel@mozilla.com>
date Wed, 20 Jun 2012 21:34:41 -0700
parents 7f7f7313b4c4
children 56ac8bd08fa0
files bitsyblog/bitsyblog.py setup.py
diffstat 2 files changed, 7 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/bitsyblog/bitsyblog.py	Thu Nov 17 16:06:23 2011 -0800
+++ b/bitsyblog/bitsyblog.py	Wed Jun 20 21:34:41 2012 -0700
@@ -156,7 +156,8 @@
         """returns material pertaining to the root of the site"""
 
         path = request.path_info.strip('/')
-        n_links = self.number_of_links(request)
+        n_posts = self.number_of_posts(request)
+        n_links = self.number_of_links(request, n_posts)
 
         ### the front page
         if not path:
@@ -164,8 +165,6 @@
 
         ### feeds
 
-        n_posts = self.number_of_posts(request)
-
         # site rss
         if path == 'rss':
             if n_posts is None:
@@ -204,6 +203,7 @@
 
         feed = None # not an rss/atom feed by default (flag)
         n_posts = self.number_of_posts(request, user)
+        n_links = self.number_of_links(request, n_posts, user)
 
         # special paths
         if path == [ 'post' ]:
@@ -259,8 +259,6 @@
         if request.GET.get('sort') == 'forward':
             blog = list(reversed(blog))
 
-        n_links = self.number_of_links(request, user)
-
         # write the blog
         if request.GET.get('format') == 'text':
             content = self.text_blog(blog)
@@ -501,13 +499,11 @@
         if n_posts is not None:
             try:
                 n_posts = int(n_posts)
-                if n_links > 0 and n_links > n_posts:
-                    n_links = n_posts # don't display more links than posts
             except (TypeError, ValueError):
                 n_posts = None
         return n_posts
 
-    def number_of_links(self, request, user=None):
+    def number_of_links(self, request, n_posts=None, user=None):
         """return the number of links to display in the navigation"""
         n_links = request.GET.get('n')
         if n_links == 'all':
@@ -516,6 +512,8 @@
             n_links = int(n_links)
         except (TypeError, ValueError):
             n_links = self.n_links
+        if n_posts and n_links > 0 and n_links > n_posts:
+            n_links = n_posts # don't display more links than posts
         return n_links
 
     def get_blog(self, user, path, role='public', n_items=None):
--- a/setup.py	Thu Nov 17 16:06:23 2011 -0800
+++ b/setup.py	Wed Jun 20 21:34:41 2012 -0700
@@ -1,7 +1,7 @@
 from setuptools import setup, find_packages
 import sys, os
 
-version = '2.4.1'
+version = '2.4.2'
 
 try:
     description = file('README.txt').read()