Ensure pagination is retained on invalid upload

Otherwise hidden Search tab causes web browser to load _every_ image in the system.
This commit is contained in:
riceyrice 2016-06-03 13:12:56 +01:00 committed by Matt Westcott
parent 64132728d1
commit cd0f8381cd
4 changed files with 23 additions and 3 deletions

View file

@ -18,7 +18,8 @@ Changelog
* Fix: Link tooltip now shows correct urls for newly inserted document links (Matt Westcott)
* Fix: Now page chooser (in a rich text editor) opens up at the link's parent page, rather than at the page itself (Matt Westcott)
* Fix: Reverted fix for explorer menu scrolling with page content, as it blocked access to menus that exceed screen height
* Fix: Image listing in the image chooser no longer becomes unpaginated after an invalid upload form submission (Stephen Rice)
1.5 (31.05.2016)
~~~~~~~~~~~~~~~~

View file

@ -21,4 +21,4 @@ Bug fixes
* Link tooltip now shows correct urls for newly inserted document links (Matt Westcott)
* Now page chooser (in a rich text editor) opens up at the link's parent page, rather than at the page itself (Matt Westcott)
* Reverted fix for explorer menu scrolling with page content, as it blocked access to menus that exceed screen height
* Image listing in the image chooser no longer becomes unpaginated after an invalid upload form submission (Stephen Rice)

View file

@ -490,6 +490,24 @@ class TestImageChooserUploadView(TestCase, WagtailTestUtils):
# The form should have an error
self.assertFormError(response, 'uploadform', 'file', "This field is required.")
def test_pagination_after_upload_form_error(self):
for i in range(0, 20):
Image.objects.create(
title="Test image %d" % i,
file=get_test_image_file(),
)
response = self.client.post(reverse('wagtailimages:chooser_upload'), {
'title': "Test image",
})
self.assertEqual(response.status_code, 200)
self.assertTemplateUsed(response, 'wagtailimages/chooser/chooser.html')
# The re-rendered image chooser listing should be paginated
self.assertContains(response, "Page 1 of ")
self.assertEqual(12, len(response.context['images']))
@override_settings(DEFAULT_FILE_STORAGE='wagtail.tests.dummy_external_storage.DummyExternalStorage')
def test_upload_with_external_storage(self):
response = self.client.post(reverse('wagtailimages:chooser_upload'), {

View file

@ -144,7 +144,8 @@ def chooser_upload(request):
else:
form = ImageForm(user=request.user)
images = Image.objects.order_by('title')
images = Image.objects.order_by('-created_at')
paginator, images = paginate(request, images, per_page=12)
return render_modal_workflow(
request, 'wagtailimages/chooser/chooser.html', 'wagtailimages/chooser/chooser.js',