Ticket #6852: admin_pagination.diff
File admin_pagination.diff, 3.9 KB (added by , 17 years ago) |
---|
-
django/contrib/admin/templatetags/admin_list.py
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 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 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 { -
django/contrib/admin/views/main.py
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, InvalidPage8 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 611 return mark_safe('?' + '&'.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. hits618 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 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