From 054c2e4af390c083a33c5a19093efd47def780de Mon Sep 17 00:00:00 2001 From: Adrian Holovaty Date: Tue, 25 Mar 2008 05:20:55 +0000 Subject: [PATCH] Fixed #6852 -- Converted the admin to use the new paginator, to remove DeprecationWarnings. Thanks for the patch, nickefford git-svn-id: http://code.djangoproject.com/svn/django/trunk@7363 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/contrib/admin/templatetags/admin_list.py | 12 ++++++------ django/contrib/admin/views/main.py | 8 ++++---- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/django/contrib/admin/templatetags/admin_list.py b/django/contrib/admin/templatetags/admin_list.py index e45b6ed0bb..6db59ea338 100644 --- a/django/contrib/admin/templatetags/admin_list.py +++ b/django/contrib/admin/templatetags/admin_list.py @@ -22,7 +22,7 @@ def paginator_number(cl,i): elif i == cl.page_num: return mark_safe(u'%d ' % (i+1)) else: - return mark_safe(u'%d ' % (cl.get_query_string({PAGE_VAR: i}), (i == cl.paginator.pages-1 and ' class="end"' or ''), i+1)) + return mark_safe(u'%d ' % (cl.get_query_string({PAGE_VAR: i}), (i == cl.paginator.num_pages-1 and ' class="end"' or ''), i+1)) paginator_number = register.simple_tag(paginator_number) def pagination(cl): @@ -37,8 +37,8 @@ def pagination(cl): # If there are 10 or fewer pages, display links to every page. # Otherwise, do some fancy - if paginator.pages <= 10: - page_range = range(paginator.pages) + if paginator.num_pages <= 10: + page_range = range(paginator.num_pages) else: # Insert "smart" pagination links, so that there are always ON_ENDS # links at either end of the list of pages, and there are always @@ -50,12 +50,12 @@ def pagination(cl): page_range.extend(range(page_num - ON_EACH_SIDE, page_num + 1)) else: page_range.extend(range(0, page_num + 1)) - if page_num < (paginator.pages - ON_EACH_SIDE - ON_ENDS - 1): + if page_num < (paginator.num_pages - ON_EACH_SIDE - ON_ENDS - 1): page_range.extend(range(page_num + 1, page_num + ON_EACH_SIDE + 1)) page_range.append(DOT) - page_range.extend(range(paginator.pages - ON_ENDS, paginator.pages)) + page_range.extend(range(paginator.num_pages - ON_ENDS, paginator.num_pages)) else: - page_range.extend(range(page_num + 1, paginator.pages)) + page_range.extend(range(page_num + 1, paginator.num_pages)) need_show_all_link = cl.can_show_all and not cl.show_all and cl.multi_page return { diff --git a/django/contrib/admin/views/main.py b/django/contrib/admin/views/main.py index 9786935bf8..55f8ae4c32 100644 --- a/django/contrib/admin/views/main.py +++ b/django/contrib/admin/views/main.py @@ -5,7 +5,7 @@ from django.contrib.admin.views.decorators import staff_member_required from django.views.decorators.cache import never_cache from django.contrib.contenttypes.models import ContentType from django.core.exceptions import ImproperlyConfigured, ObjectDoesNotExist, PermissionDenied -from django.core.paginator import ObjectPaginator, InvalidPage +from django.core.paginator import QuerySetPaginator, InvalidPage from django.shortcuts import get_object_or_404, render_to_response from django.db import models from django.db.models.query import handle_legacy_orderlist, QuerySet @@ -611,11 +611,11 @@ class ChangeList(object): return mark_safe('?' + '&'.join([u'%s=%s' % (k, v) for k, v in p.items()]).replace(' ', '%20')) def get_results(self, request): - paginator = ObjectPaginator(self.query_set, self.lookup_opts.admin.list_per_page) + paginator = QuerySetPaginator(self.query_set, self.lookup_opts.admin.list_per_page) # Get the number of objects, with admin filters applied. try: - result_count = paginator.hits + result_count = paginator.count # Naked except! Because we don't have any other way of validating # "params". They might be invalid if the keyword arguments are # incorrect, or if the values are not in the correct type (which would @@ -640,7 +640,7 @@ class ChangeList(object): result_list = list(self.query_set) else: try: - result_list = paginator.get_page(self.page_num) + result_list = paginator.page(self.page_num+1).object_list except InvalidPage: result_list = ()