From d32637d81b6b4adf6440bead756fb5a063e4d28d Mon Sep 17 00:00:00 2001 From: Claude Paroz Date: Sat, 7 Dec 2013 14:11:27 +0100 Subject: [PATCH] [1.6.x] Fixed #21510 -- Readded search reset link in changelist search bar Thanks moritz.pfeiffer at alp-phone.ch for the report and Tim Graham for the initial patch. Backport of c7c647419c from master. --- django/contrib/admin/views/main.py | 2 +- docs/releases/1.6.1.txt | 2 ++ tests/admin_views/tests.py | 15 ++++++++++++--- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/django/contrib/admin/views/main.py b/django/contrib/admin/views/main.py index 56462dece8..e7b23913e9 100644 --- a/django/contrib/admin/views/main.py +++ b/django/contrib/admin/views/main.py @@ -223,7 +223,7 @@ class ChangeList(six.with_metaclass(RenameChangeListMethods)): # Perform a slight optimization: # full_result_count is equal to paginator.count if no filters # were applied - if self.get_filters_params(): + if self.get_filters_params() or self.params.get(SEARCH_VAR): full_result_count = self.root_queryset.count() else: full_result_count = result_count diff --git a/docs/releases/1.6.1.txt b/docs/releases/1.6.1.txt index ec81848d19..f222756a33 100644 --- a/docs/releases/1.6.1.txt +++ b/docs/releases/1.6.1.txt @@ -47,3 +47,5 @@ Bug fixes * Fixed password hash upgrade when changing the iteration count (#21535). * Fixed a bug in the debug view when the urlconf only contains one element (#21530). +* Re-added missing search result count and reset link in changelist admin view + (#21510). diff --git a/tests/admin_views/tests.py b/tests/admin_views/tests.py index 8a53dee3ea..f26b0ab01b 100644 --- a/tests/admin_views/tests.py +++ b/tests/admin_views/tests.py @@ -2242,6 +2242,15 @@ class AdminSearchTest(TestCase): self.assertContains(response, "\n1 pluggable search person\n") self.assertContains(response, "Amy") + def test_reset_link(self): + """ + Test presence of reset link in search bar ("1 result (_x total_)"). + """ + response = self.client.get('/test_admin/admin/admin_views/person/?q=Gui') + self.assertContains(response, + """1 result (3 total)""", + html=True) + @override_settings(PASSWORD_HASHERS=('django.contrib.auth.hashers.SHA1PasswordHasher',)) class AdminInheritedInlinesTest(TestCase): @@ -2665,17 +2674,17 @@ class AdminCustomQuerysetTest(TestCase): resp = self.client.get('/test_admin/admin/admin_views/person/') self.assertEqual(resp.context['selection_note'], '0 of 2 selected') self.assertEqual(resp.context['selection_note_all'], 'All 2 selected') - with self.assertNumQueries(4): + # here one more count(*) query will run, because filters were applied + with self.assertNumQueries(5): extra = {'q': 'not_in_name'} resp = self.client.get('/test_admin/admin/admin_views/person/', extra) self.assertEqual(resp.context['selection_note'], '0 of 0 selected') self.assertEqual(resp.context['selection_note_all'], 'All 0 selected') - with self.assertNumQueries(4): + with self.assertNumQueries(5): extra = {'q': 'person'} resp = self.client.get('/test_admin/admin/admin_views/person/', extra) self.assertEqual(resp.context['selection_note'], '0 of 2 selected') self.assertEqual(resp.context['selection_note_all'], 'All 2 selected') - # here one more count(*) query will run, because filters were applied with self.assertNumQueries(5): extra = {'gender__exact': '1'} resp = self.client.get('/test_admin/admin/admin_views/person/', extra)