From c7c647419cb857fe53cf1368c10223c6e042c216 Mon Sep 17 00:00:00 2001 From: Claude Paroz Date: Sat, 7 Dec 2013 14:11:27 +0100 Subject: [PATCH] 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. --- 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 8649b10caaa..dccab55de4e 100644 --- a/django/contrib/admin/views/main.py +++ b/django/contrib/admin/views/main.py @@ -217,7 +217,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 ec81848d192..f222756a33a 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 2cc0618cc3c..a0319ee8942 100644 --- a/tests/admin_views/tests.py +++ b/tests/admin_views/tests.py @@ -2275,6 +2275,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): @@ -2716,17 +2725,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)