Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #6852 -- Converted the admin to use the new paginator, to remov…

…e DeprecationWarnings. Thanks for the patch, nickefford

git-svn-id: http://code.djangoproject.com/svn/django/trunk@7363 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 054c2e4af390c083a33c5a19093efd47def780de 1 parent 3d779ef
Adrian Holovaty authored March 25, 2008
12  django/contrib/admin/templatetags/admin_list.py
@@ -22,7 +22,7 @@ def paginator_number(cl,i):
22 22
     elif i == cl.page_num:
23 23
         return mark_safe(u'<span class="this-page">%d</span> ' % (i+1))
24 24
     else:
25  
-        return mark_safe(u'<a href="%s"%s>%d</a> ' % (cl.get_query_string({PAGE_VAR: i}), (i == cl.paginator.pages-1 and ' class="end"' or ''), i+1))
  25
+        return mark_safe(u'<a href="%s"%s>%d</a> ' % (cl.get_query_string({PAGE_VAR: i}), (i == cl.paginator.num_pages-1 and ' class="end"' or ''), i+1))
26 26
 paginator_number = register.simple_tag(paginator_number)
27 27
 
28 28
 def pagination(cl):
@@ -37,8 +37,8 @@ def pagination(cl):
37 37
 
38 38
         # If there are 10 or fewer pages, display links to every page.
39 39
         # Otherwise, do some fancy
40  
-        if paginator.pages <= 10:
41  
-            page_range = range(paginator.pages)
  40
+        if paginator.num_pages <= 10:
  41
+            page_range = range(paginator.num_pages)
42 42
         else:
43 43
             # Insert "smart" pagination links, so that there are always ON_ENDS
44 44
             # links at either end of the list of pages, and there are always
@@ -50,12 +50,12 @@ def pagination(cl):
50 50
                 page_range.extend(range(page_num - ON_EACH_SIDE, page_num + 1))
51 51
             else:
52 52
                 page_range.extend(range(0, page_num + 1))
53  
-            if page_num < (paginator.pages - ON_EACH_SIDE - ON_ENDS - 1):
  53
+            if page_num < (paginator.num_pages - ON_EACH_SIDE - ON_ENDS - 1):
54 54
                 page_range.extend(range(page_num + 1, page_num + ON_EACH_SIDE + 1))
55 55
                 page_range.append(DOT)
56  
-                page_range.extend(range(paginator.pages - ON_ENDS, paginator.pages))
  56
+                page_range.extend(range(paginator.num_pages - ON_ENDS, paginator.num_pages))
57 57
             else:
58  
-                page_range.extend(range(page_num + 1, paginator.pages))
  58
+                page_range.extend(range(page_num + 1, paginator.num_pages))
59 59
 
60 60
     need_show_all_link = cl.can_show_all and not cl.show_all and cl.multi_page
61 61
     return {
8  django/contrib/admin/views/main.py
@@ -5,7 +5,7 @@
5 5
 from django.views.decorators.cache import never_cache
6 6
 from django.contrib.contenttypes.models import ContentType
7 7
 from django.core.exceptions import ImproperlyConfigured, ObjectDoesNotExist, PermissionDenied
8  
-from django.core.paginator import ObjectPaginator, InvalidPage
  8
+from django.core.paginator import QuerySetPaginator, InvalidPage
9 9
 from django.shortcuts import get_object_or_404, render_to_response
10 10
 from django.db import models
11 11
 from django.db.models.query import handle_legacy_orderlist, QuerySet
@@ -611,11 +611,11 @@ def get_query_string(self, new_params=None, remove=None):
611 611
         return mark_safe('?' + '&amp;'.join([u'%s=%s' % (k, v) for k, v in p.items()]).replace(' ', '%20'))
612 612
 
613 613
     def get_results(self, request):
614  
-        paginator = ObjectPaginator(self.query_set, self.lookup_opts.admin.list_per_page)
  614
+        paginator = QuerySetPaginator(self.query_set, self.lookup_opts.admin.list_per_page)
615 615
 
616 616
         # Get the number of objects, with admin filters applied.
617 617
         try:
618  
-            result_count = paginator.hits
  618
+            result_count = paginator.count
619 619
         # Naked except! Because we don't have any other way of validating
620 620
         # "params". They might be invalid if the keyword arguments are
621 621
         # incorrect, or if the values are not in the correct type (which would
@@ -640,7 +640,7 @@ def get_results(self, request):
640 640
             result_list = list(self.query_set)
641 641
         else:
642 642
             try:
643  
-                result_list = paginator.get_page(self.page_num)
  643
+                result_list = paginator.page(self.page_num+1).object_list
644 644
             except InvalidPage:
645 645
                 result_list = ()
646 646
 

0 notes on commit 054c2e4

Please sign in to comment.
Something went wrong with that request. Please try again.