From 5d30b71366b179449b54cd16b87ef7380338c064 Mon Sep 17 00:00:00 2001 From: Stephen Burrows Date: Wed, 11 Aug 2010 17:24:43 -0400 Subject: [PATCH] Adjusted the paginate function to only attempt a length check if per_page is valid. Addresses bug #19. --- utils.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/utils.py b/utils.py index efd9f98..6fc2cff 100644 --- a/utils.py +++ b/utils.py @@ -74,15 +74,15 @@ def paginate(objects, per_page=None, page_number=1): except (TypeError, ValueError): # Then either it wasn't set or it was set to an invalid value paginator = page = None - - # There also shouldn't be pagination if the list is too short. Try count() - # first - good chance it's a queryset, where count is more efficient. - try: - if objects.count() <= per_page: - paginator = page = None - except AttributeError: - if len(objects) <= per_page: - paginator = page = None + else: + # There also shouldn't be pagination if the list is too short. Try count() + # first - good chance it's a queryset, where count is more efficient. + try: + if objects.count() <= per_page: + paginator = page = None + except AttributeError: + if len(objects) <= per_page: + paginator = page = None try: return paginator, page, objects -- 2.20.1