Ensure 'next' param on image / doc listings always links back to index page, not results view

Fixes . When results listings are generated as partial AJAX responses through the listing_results review, the 'next' parameter on those results should point back to the main 'index' view so that on return from the edit view, the user gets back a full page rather than a partial response.
pull/9096/head
Matt Westcott 2022-04-07 14:25:28 +01:00
rodzic 6748f0fa69
commit 8aab0b35a6
4 zmienionych plików z 53 dodań i 2 usunięć
wagtail

Wyświetl plik

@ -131,6 +131,25 @@ class TestDocumentIndexView(TestCase, WagtailTestUtils):
self.assertContains(response, '%s?next=%s' % (edit_url, next_url))
class TestDocumentListingResultsView(TestCase, WagtailTestUtils):
def setUp(self):
self.login()
def get(self, params={}):
return self.client.get(reverse("wagtaildocs:listing_results"), params)
def test_search(self):
doc = models.Document.objects.create(title="A boring report")
response = self.get({"q": "boring"})
self.assertEqual(response.status_code, 200)
# 'next' param on edit page link should point back to the documents index, not the results view
self.assertContains(
response,
"/admin/documents/edit/%d/?next=/admin/documents/%%3Fq%%3Dboring" % doc.id,
)
class TestDocumentAddView(TestCase, WagtailTestUtils):
def setUp(self):
self.login()

Wyświetl plik

@ -69,12 +69,17 @@ class BaseListingView(TemplateView):
paginator = Paginator(documents, per_page=20)
documents = paginator.get_page(self.request.GET.get('p'))
next_url = reverse("wagtaildocs:index")
request_query_string = self.request.META.get("QUERY_STRING")
if request_query_string:
next_url += "?" + request_query_string
context.update({
'ordering': ordering,
'documents': documents,
'query_string': query_string,
'is_searching': bool(query_string),
'next': self.request.get_full_path(),
'next': next_url,
})
return context

Wyświetl plik

@ -196,6 +196,28 @@ class TestImageIndexView(TestCase, WagtailTestUtils):
)
class TestImageListingResultsView(TestCase, WagtailTestUtils):
def setUp(self):
self.login()
def get(self, params={}):
return self.client.get(reverse("wagtailimages:listing_results"), params)
def test_search(self):
monster = Image.objects.create(
title="A scary monster",
file=get_test_image_file(),
)
response = self.get({"q": "monster"})
self.assertEqual(response.status_code, 200)
# 'next' param on edit page link should point back to the images index, not the results view
self.assertContains(
response,
"/admin/images/%d/?next=/admin/images/%%3Fq%%3Dmonster" % monster.id,
)
class TestImageAddView(TestCase, WagtailTestUtils):
def setUp(self):
self.login()

Wyświetl plik

@ -79,11 +79,16 @@ class BaseListingView(TemplateView):
paginator = Paginator(images, per_page=INDEX_PAGE_SIZE)
images = paginator.get_page(self.request.GET.get('p'))
next_url = reverse("wagtailimages:index")
request_query_string = self.request.META.get("QUERY_STRING")
if request_query_string:
next_url += "?" + request_query_string
context.update({
'images': images,
'query_string': query_string,
'is_searching': bool(query_string),
'next': self.request.get_full_path(),
'next': next_url,
})
return context