mirror of
				https://github.com/django/django.git
				synced 2025-10-31 01:25:32 +00:00 
			
		
		
		
	[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.
			
			
This commit is contained in:
		| @@ -223,7 +223,7 @@ class ChangeList(six.with_metaclass(RenameChangeListMethods)): | |||||||
|         # Perform a slight optimization: |         # Perform a slight optimization: | ||||||
|         # full_result_count is equal to paginator.count if no filters |         # full_result_count is equal to paginator.count if no filters | ||||||
|         # were applied |         # 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() |             full_result_count = self.root_queryset.count() | ||||||
|         else: |         else: | ||||||
|             full_result_count = result_count |             full_result_count = result_count | ||||||
|   | |||||||
| @@ -47,3 +47,5 @@ Bug fixes | |||||||
| * Fixed password hash upgrade when changing the iteration count (#21535). | * Fixed password hash upgrade when changing the iteration count (#21535). | ||||||
| * Fixed a bug in the debug view when the urlconf only contains one element | * Fixed a bug in the debug view when the urlconf only contains one element | ||||||
|   (#21530). |   (#21530). | ||||||
|  | * Re-added missing search result count and reset link in changelist admin view | ||||||
|  |   (#21510). | ||||||
|   | |||||||
| @@ -2242,6 +2242,15 @@ class AdminSearchTest(TestCase): | |||||||
|         self.assertContains(response, "\n1 pluggable search person\n") |         self.assertContains(response, "\n1 pluggable search person\n") | ||||||
|         self.assertContains(response, "Amy") |         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, | ||||||
|  |             """<span class="small quiet">1 result (<a href="?">3 total</a>)</span>""", | ||||||
|  |             html=True) | ||||||
|  |  | ||||||
|  |  | ||||||
| @override_settings(PASSWORD_HASHERS=('django.contrib.auth.hashers.SHA1PasswordHasher',)) | @override_settings(PASSWORD_HASHERS=('django.contrib.auth.hashers.SHA1PasswordHasher',)) | ||||||
| class AdminInheritedInlinesTest(TestCase): | class AdminInheritedInlinesTest(TestCase): | ||||||
| @@ -2665,17 +2674,17 @@ class AdminCustomQuerysetTest(TestCase): | |||||||
|             resp = self.client.get('/test_admin/admin/admin_views/person/') |             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'], '0 of 2 selected') | ||||||
|             self.assertEqual(resp.context['selection_note_all'], 'All 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'} |             extra = {'q': 'not_in_name'} | ||||||
|             resp = self.client.get('/test_admin/admin/admin_views/person/', extra) |             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'], '0 of 0 selected') | ||||||
|             self.assertEqual(resp.context['selection_note_all'], 'All 0 selected') |             self.assertEqual(resp.context['selection_note_all'], 'All 0 selected') | ||||||
|         with self.assertNumQueries(4): |         with self.assertNumQueries(5): | ||||||
|             extra = {'q': 'person'} |             extra = {'q': 'person'} | ||||||
|             resp = self.client.get('/test_admin/admin/admin_views/person/', extra) |             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'], '0 of 2 selected') | ||||||
|             self.assertEqual(resp.context['selection_note_all'], 'All 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): |         with self.assertNumQueries(5): | ||||||
|             extra = {'gender__exact': '1'} |             extra = {'gender__exact': '1'} | ||||||
|             resp = self.client.get('/test_admin/admin/admin_views/person/', extra) |             resp = self.client.get('/test_admin/admin/admin_views/person/', extra) | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user