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