From da310cff674aa3d91f7e54772faf828a46071812 Mon Sep 17 00:00:00 2001 From: Jacob Kaplan-Moss Date: Mon, 27 Feb 2006 23:34:39 +0000 Subject: [PATCH] Fixed #1033 -- pagination in object_list generic views now use 1-indexed page numbers in the URL. Thanks, Tom Tobin. git-svn-id: http://code.djangoproject.com/svn/django/trunk@2426 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/views/generic/list_detail.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/django/views/generic/list_detail.py b/django/views/generic/list_detail.py index d81d46f52b..f76b984be1 100644 --- a/django/views/generic/list_detail.py +++ b/django/views/generic/list_detail.py @@ -39,22 +39,22 @@ def object_list(request, app_label, module_name, paginate_by=None, allow_empty=F lookup_kwargs = extra_lookup_kwargs.copy() if paginate_by: paginator = ObjectPaginator(mod, lookup_kwargs, paginate_by) - page = request.GET.get('page', 0) + page = request.GET.get('page', 1) try: - object_list = paginator.get_page(page) - except InvalidPage: - if page == 0 and allow_empty: + page = int(page) + object_list = paginator.get_page(page - 1) + except (InvalidPage, ValueError): + if page == 1 and allow_empty: object_list = [] else: raise Http404 - page = int(page) c = DjangoContext(request, { 'object_list': object_list, 'is_paginated': paginator.pages > 1, 'results_per_page': paginate_by, - 'has_next': paginator.has_next_page(page), - 'has_previous': paginator.has_previous_page(page), - 'page': page + 1, + 'has_next': paginator.has_next_page(page - 1), + 'has_previous': paginator.has_previous_page(page - 1), + 'page': page, 'next': page + 1, 'previous': page - 1, 'pages': paginator.pages,