Rectified bugs that were accidentally committed in r14997. Thanks for the heads-up, Alex Gaynor.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@15011 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
745c255a19
commit
af5ad1116c
|
@ -422,6 +422,9 @@ class ModelAdmin(BaseModelAdmin):
|
|||
for inline in self.inline_instances:
|
||||
yield inline.get_formset(request, obj)
|
||||
|
||||
def get_paginator(self, request, queryset, per_page, orphans=0, allow_empty_first_page=True):
|
||||
return self.paginator(queryset, per_page, orphans, allow_empty_first_page)
|
||||
|
||||
def log_addition(self, request, object):
|
||||
"""
|
||||
Log that an object has been successfully added.
|
||||
|
@ -979,7 +982,7 @@ class ModelAdmin(BaseModelAdmin):
|
|||
try:
|
||||
cl = ChangeList(request, self.model, list_display, self.list_display_links,
|
||||
self.list_filter, self.date_hierarchy, self.search_fields,
|
||||
self.list_select_related, self.list_per_page, self.list_editable, self.paginator, self)
|
||||
self.list_select_related, self.list_per_page, self.list_editable, self)
|
||||
except IncorrectLookupParameters:
|
||||
# Wacky lookup parameters were given, so redirect to the main
|
||||
# changelist page, without parameters, and pass an 'invalid=1'
|
||||
|
|
|
@ -26,7 +26,7 @@ ERROR_FLAG = 'e'
|
|||
EMPTY_CHANGELIST_VALUE = '(None)'
|
||||
|
||||
class ChangeList(object):
|
||||
def __init__(self, request, model, list_display, list_display_links, list_filter, date_hierarchy, search_fields, list_select_related, list_per_page, list_editable, paginator, model_admin):
|
||||
def __init__(self, request, model, list_display, list_display_links, list_filter, date_hierarchy, search_fields, list_select_related, list_per_page, list_editable, model_admin):
|
||||
self.model = model
|
||||
self.opts = model._meta
|
||||
self.lookup_opts = self.opts
|
||||
|
@ -40,7 +40,6 @@ class ChangeList(object):
|
|||
self.list_per_page = list_per_page
|
||||
self.list_editable = list_editable
|
||||
self.model_admin = model_admin
|
||||
self.paginator = paginator
|
||||
|
||||
# Get search parameters from the query string.
|
||||
try:
|
||||
|
@ -95,7 +94,7 @@ class ChangeList(object):
|
|||
return '?%s' % urlencode(p)
|
||||
|
||||
def get_results(self, request):
|
||||
paginator = self.get_paginator(self.query_set, self.list_per_page)
|
||||
paginator = self.model_admin.get_paginator(request, self.query_set, self.list_per_page)
|
||||
# Get the number of objects, with admin filters applied.
|
||||
result_count = paginator.count
|
||||
|
||||
|
@ -245,6 +244,3 @@ class ChangeList(object):
|
|||
|
||||
def url_for_result(self, result):
|
||||
return "%s/" % quote(getattr(result, self.pk_attname))
|
||||
|
||||
def get_paginator(self, queryset, per_page, orphans=0, allow_empty_first_page=True):
|
||||
return self.paginator(queryset, per_page, orphans, allow_empty_first_page)
|
||||
|
|
|
@ -524,7 +524,7 @@ subclass::
|
|||
:class:`django.core.paginator.Paginator` is used. If the custom paginator
|
||||
class doesn't have the same constructor interface as
|
||||
:class:`django.core.paginator.Paginator`, you will also need to
|
||||
provide an implementation for :meth:`MultipleObjectMixin.get_paginator`.
|
||||
provide an implementation for :meth:`ModelAdmin.get_paginator`.
|
||||
|
||||
.. attribute:: ModelAdmin.prepopulated_fields
|
||||
|
||||
|
|
|
@ -17,8 +17,7 @@ class ChangeListTests(TransactionTestCase):
|
|||
m = ChildAdmin(Child, admin.site)
|
||||
cl = ChangeList(MockRequest(), Child, m.list_display, m.list_display_links,
|
||||
m.list_filter, m.date_hierarchy, m.search_fields,
|
||||
m.list_select_related, m.list_per_page, m.list_editable,
|
||||
m.paginator, m)
|
||||
m.list_select_related, m.list_per_page, m.list_editable, m)
|
||||
self.assertEqual(cl.query_set.query.select_related, {'parent': {'name': {}}})
|
||||
|
||||
def test_result_list_html(self):
|
||||
|
@ -32,8 +31,7 @@ class ChangeListTests(TransactionTestCase):
|
|||
m = ChildAdmin(Child, admin.site)
|
||||
cl = ChangeList(request, Child, m.list_display, m.list_display_links,
|
||||
m.list_filter, m.date_hierarchy, m.search_fields,
|
||||
m.list_select_related, m.list_per_page, m.list_editable,
|
||||
m.paginator, m)
|
||||
m.list_select_related, m.list_per_page, m.list_editable, m)
|
||||
cl.formset = None
|
||||
template = Template('{% load admin_list %}{% spaceless %}{% result_list cl %}{% endspaceless %}')
|
||||
context = Context({'cl': cl})
|
||||
|
@ -62,8 +60,7 @@ class ChangeListTests(TransactionTestCase):
|
|||
m.list_editable = ['name']
|
||||
cl = ChangeList(request, Child, m.list_display, m.list_display_links,
|
||||
m.list_filter, m.date_hierarchy, m.search_fields,
|
||||
m.list_select_related, m.list_per_page, m.list_editable,
|
||||
m.paginator, m)
|
||||
m.list_select_related, m.list_per_page, m.list_editable, m)
|
||||
FormSet = m.get_changelist_formset(request)
|
||||
cl.formset = FormSet(queryset=cl.result_list)
|
||||
template = Template('{% load admin_list %}{% spaceless %}{% result_list cl %}{% endspaceless %}')
|
||||
|
@ -97,8 +94,7 @@ class ChangeListTests(TransactionTestCase):
|
|||
self.assertRaises(IncorrectLookupParameters, lambda: \
|
||||
ChangeList(request, Child, m.list_display, m.list_display_links,
|
||||
m.list_filter, m.date_hierarchy, m.search_fields,
|
||||
m.list_select_related, m.list_per_page, m.list_editable,
|
||||
m.paginator, m))
|
||||
m.list_select_related, m.list_per_page, m.list_editable, m))
|
||||
|
||||
def test_custom_paginator(self):
|
||||
new_parent = Parent.objects.create(name='parent')
|
||||
|
@ -114,8 +110,7 @@ class ChangeListTests(TransactionTestCase):
|
|||
|
||||
cl = ChangeList(request, Child, m.list_display, m.list_display_links,
|
||||
m.list_filter, m.date_hierarchy, m.search_fields,
|
||||
m.list_select_related, m.list_per_page, m.list_editable,
|
||||
m.paginator, m)
|
||||
m.list_select_related, m.list_per_page, m.list_editable, m)
|
||||
|
||||
cl.get_results(request)
|
||||
self.assertIsInstance(cl.paginator, CustomPaginator)
|
||||
|
@ -133,8 +128,5 @@ class MockRequest(object):
|
|||
|
||||
class CustomPaginator(Paginator):
|
||||
def __init__(self, queryset, page_size, orphans=0, allow_empty_first_page=True):
|
||||
super(CustomPaginator, self).__init__(
|
||||
queryset,
|
||||
5,
|
||||
orphans=2,
|
||||
super(CustomPaginator, self).__init__(queryset, 5, orphans=2,
|
||||
allow_empty_first_page=allow_empty_first_page)
|
||||
|
|
Loading…
Reference in New Issue