From af5ad1116cacda13f48403c5c13af55d94b36a90 Mon Sep 17 00:00:00 2001 From: Jannis Leidel Date: Tue, 21 Dec 2010 19:19:04 +0000 Subject: [PATCH] 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 --- django/contrib/admin/options.py | 5 ++++- django/contrib/admin/views/main.py | 8 ++------ docs/ref/contrib/admin/index.txt | 2 +- .../regressiontests/admin_changelist/tests.py | 20 ++++++------------- 4 files changed, 13 insertions(+), 22 deletions(-) diff --git a/django/contrib/admin/options.py b/django/contrib/admin/options.py index ae715a17c4..5a35e4fbf5 100644 --- a/django/contrib/admin/options.py +++ b/django/contrib/admin/options.py @@ -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' diff --git a/django/contrib/admin/views/main.py b/django/contrib/admin/views/main.py index 288ecac875..448c6377f3 100644 --- a/django/contrib/admin/views/main.py +++ b/django/contrib/admin/views/main.py @@ -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) diff --git a/docs/ref/contrib/admin/index.txt b/docs/ref/contrib/admin/index.txt index 1e3098d7db..d79a9f8a7d 100644 --- a/docs/ref/contrib/admin/index.txt +++ b/docs/ref/contrib/admin/index.txt @@ -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 diff --git a/tests/regressiontests/admin_changelist/tests.py b/tests/regressiontests/admin_changelist/tests.py index 1fbd76f34a..fca1b9e57c 100644 --- a/tests/regressiontests/admin_changelist/tests.py +++ b/tests/regressiontests/admin_changelist/tests.py @@ -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)