mirror of
				https://github.com/django/django.git
				synced 2025-10-28 16:16:12 +00:00 
			
		
		
		
	Fixed #14312 -- Raising an `IncorrectLookupParameters` if the page number given to an admin change list exceeds the number of the last page. Thanks, mk.
				
					
				
			git-svn-id: http://code.djangoproject.com/svn/django/trunk@14889 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
		| @@ -117,7 +117,7 @@ class ChangeList(object): | |||||||
|             try: |             try: | ||||||
|                 result_list = paginator.page(self.page_num+1).object_list |                 result_list = paginator.page(self.page_num+1).object_list | ||||||
|             except InvalidPage: |             except InvalidPage: | ||||||
|                 result_list = () |                 raise IncorrectLookupParameters | ||||||
|  |  | ||||||
|         self.result_count = result_count |         self.result_count = result_count | ||||||
|         self.full_result_count = full_result_count |         self.full_result_count = full_result_count | ||||||
|   | |||||||
| @@ -1,4 +1,5 @@ | |||||||
| from django.contrib import admin | from django.contrib import admin | ||||||
|  | from django.contrib.admin.options import IncorrectLookupParameters | ||||||
| from django.contrib.admin.views.main import ChangeList | from django.contrib.admin.views.main import ChangeList | ||||||
| from django.template import Context, Template | from django.template import Context, Template | ||||||
| from django.test import TransactionTestCase | from django.test import TransactionTestCase | ||||||
| @@ -71,6 +72,28 @@ class ChangeListTests(TransactionTestCase): | |||||||
|         self.assertFalse('<td>%s</td>' % editable_name_field == -1, |         self.assertFalse('<td>%s</td>' % editable_name_field == -1, | ||||||
|             'Failed to find "name" list_editable field in: %s' % table_output) |             'Failed to find "name" list_editable field in: %s' % table_output) | ||||||
|  |  | ||||||
|  |     def test_result_list_editable(self): | ||||||
|  |         """ | ||||||
|  |         Regression test for #14312: list_editable with pagination | ||||||
|  |         """ | ||||||
|  |  | ||||||
|  |         new_parent = Parent.objects.create(name='parent') | ||||||
|  |         for i in range(200): | ||||||
|  |             new_child = Child.objects.create(name='name %s' % i, parent=new_parent) | ||||||
|  |         request = MockRequest() | ||||||
|  |         request.GET['p'] = -1 # Anything outside range | ||||||
|  |         m = ChildAdmin(Child, admin.site) | ||||||
|  |  | ||||||
|  |         # Test with list_editable fields | ||||||
|  |         m.list_display = ['id', 'name', 'parent'] | ||||||
|  |         m.list_display_links = ['id'] | ||||||
|  |         m.list_editable = ['name'] | ||||||
|  |         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)) | ||||||
|  |  | ||||||
|  |  | ||||||
| class ChildAdmin(admin.ModelAdmin): | class ChildAdmin(admin.ModelAdmin): | ||||||
|     list_display = ['name', 'parent'] |     list_display = ['name', 'parent'] | ||||||
|     def queryset(self, request): |     def queryset(self, request): | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user