kopia lustrzana https://github.com/wagtail/wagtail
Add next parameter to form submission delete view and bulk action
rodzic
74df95d049
commit
4bfab460a4
|
@ -17,6 +17,7 @@
|
|||
</p>
|
||||
<form action="{% url 'wagtailforms:delete_submissions' page.id %}?{{ request.GET.urlencode }}" method="POST">
|
||||
{% csrf_token %}
|
||||
<input type="hidden" value="{{ next_url }}" name="next">
|
||||
<input type="submit" value="{% trans 'Delete' %}" class="button serious">
|
||||
</form>
|
||||
</div>
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
{% load i18n %}
|
||||
{% block results %}
|
||||
<form class="w-overflow-auto" data-controller="w-bulk" data-w-bulk-action-inactive-class="w-invisible" action="{% url 'wagtailforms:delete_submissions' form_page.id %}" method="get">
|
||||
<input type="hidden" value="{{ next_url }}" name="next">
|
||||
<table class="listing">
|
||||
<col />
|
||||
<col />
|
||||
|
|
|
@ -481,10 +481,8 @@ class TestFormsSubmissionsList(WagtailTestUtils, TestCase):
|
|||
def test_list_submissions_pagination(self):
|
||||
self.make_list_submissions()
|
||||
|
||||
response = self.client.get(
|
||||
reverse("wagtailforms:list_submissions", args=(self.form_page.id,)),
|
||||
{"p": 2},
|
||||
)
|
||||
list_url = reverse("wagtailforms:list_submissions", args=(self.form_page.id,))
|
||||
response = self.client.get(list_url, {"p": 2})
|
||||
|
||||
# Check response
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
@ -493,6 +491,18 @@ class TestFormsSubmissionsList(WagtailTestUtils, TestCase):
|
|||
# Check that we got the correct page
|
||||
self.assertEqual(response.context["page_obj"].number, 2)
|
||||
|
||||
# The delete form should have a 'next' input that points back to the list page
|
||||
# with the same pagination querystring
|
||||
soup = self.get_soup(response.content)
|
||||
delete_url = reverse(
|
||||
"wagtailforms:delete_submissions", args=(self.form_page.id,)
|
||||
)
|
||||
form = soup.find("form", {"action": delete_url})
|
||||
self.assertIsNotNone(form)
|
||||
next_input = form.find("input", {"name": "next"})
|
||||
self.assertIsNotNone(next_input)
|
||||
self.assertEqual(next_input.get("value"), f"{list_url}?p=2")
|
||||
|
||||
def test_list_submissions_pagination_invalid(self):
|
||||
self.make_list_submissions()
|
||||
|
||||
|
@ -1184,10 +1194,8 @@ class TestCustomFormsSubmissionsList(WagtailTestUtils, TestCase):
|
|||
def test_list_submissions_pagination(self):
|
||||
self.make_list_submissions()
|
||||
|
||||
response = self.client.get(
|
||||
reverse("wagtailforms:list_submissions", args=(self.form_page.id,)),
|
||||
{"p": 2},
|
||||
)
|
||||
list_url = reverse("wagtailforms:list_submissions", args=(self.form_page.id,))
|
||||
response = self.client.get(list_url, {"p": 2})
|
||||
|
||||
# Check response
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
@ -1202,6 +1210,18 @@ class TestCustomFormsSubmissionsList(WagtailTestUtils, TestCase):
|
|||
)
|
||||
self.assertContains(response, "generated-username-", count=20)
|
||||
|
||||
# The delete form should have a 'next' input that points back to the list page
|
||||
# with the same pagination querystring
|
||||
soup = self.get_soup(response.content)
|
||||
delete_url = reverse(
|
||||
"wagtailforms:delete_submissions", args=(self.form_page.id,)
|
||||
)
|
||||
form = soup.find("form", {"action": delete_url})
|
||||
self.assertIsNotNone(form)
|
||||
next_input = form.find("input", {"name": "next"})
|
||||
self.assertIsNotNone(next_input)
|
||||
self.assertEqual(next_input.get("value"), f"{list_url}?p=2")
|
||||
|
||||
def test_list_submissions_pagination_invalid(self):
|
||||
self.make_list_submissions()
|
||||
|
||||
|
@ -1327,6 +1347,18 @@ class TestDeleteFormSubmission(WagtailTestUtils, TestCase):
|
|||
reverse("wagtailforms:list_submissions", args=(self.form_page.id,)),
|
||||
)
|
||||
|
||||
def test_delete_submission_with_next_url(self):
|
||||
list_url = reverse("wagtailforms:list_submissions", args=(self.form_page.id,))
|
||||
next_url = list_url + "?p=2"
|
||||
response = self.client.post(
|
||||
reverse("wagtailforms:delete_submissions", args=(self.form_page.id,)),
|
||||
{
|
||||
"selected-submissions": FormSubmission.objects.first().id,
|
||||
"next": next_url,
|
||||
},
|
||||
)
|
||||
self.assertRedirects(response, next_url)
|
||||
|
||||
|
||||
class TestDeleteCustomFormSubmission(WagtailTestUtils, TestCase):
|
||||
fixtures = ["test.json"]
|
||||
|
@ -1521,10 +1553,8 @@ class TestFormsWithCustomSubmissionsList(WagtailTestUtils, TestCase):
|
|||
def test_list_submissions_pagination(self):
|
||||
self.make_list_submissions()
|
||||
|
||||
response = self.client.get(
|
||||
reverse("wagtailforms:list_submissions", args=(self.form_page.id,)),
|
||||
{"p": 2},
|
||||
)
|
||||
list_url = reverse("wagtailforms:list_submissions", args=(self.form_page.id,))
|
||||
response = self.client.get(list_url, {"p": 2})
|
||||
|
||||
# Check response
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
@ -1535,6 +1565,18 @@ class TestFormsWithCustomSubmissionsList(WagtailTestUtils, TestCase):
|
|||
self.assertContains(response, "Wet my pants excited!", count=50)
|
||||
self.assertEqual(response.context["page_obj"].number, 2)
|
||||
|
||||
# The delete form should have a 'next' input that points back to the list page
|
||||
# with the same pagination querystring
|
||||
soup = self.get_soup(response.content)
|
||||
delete_url = reverse(
|
||||
"wagtailforms:delete_submissions", args=(self.form_page.id,)
|
||||
)
|
||||
form = soup.find("form", {"action": delete_url})
|
||||
self.assertIsNotNone(form)
|
||||
next_input = form.find("input", {"name": "next"})
|
||||
self.assertIsNotNone(next_input)
|
||||
self.assertEqual(next_input.get("value"), f"{list_url}?p=2")
|
||||
|
||||
def test_list_submissions_csv_export(self):
|
||||
response = self.client.get(
|
||||
reverse("wagtailforms:list_submissions", args=(self.form_page.id,)),
|
||||
|
|
|
@ -12,6 +12,7 @@ from django_filters import DateFromToRangeFilter
|
|||
from wagtail.admin import messages
|
||||
from wagtail.admin.filters import DateRangePickerWidget, WagtailFilterSet
|
||||
from wagtail.admin.ui.tables import Column, TitleColumn
|
||||
from wagtail.admin.utils import get_valid_next_url_from_request
|
||||
from wagtail.admin.views import generic
|
||||
from wagtail.admin.views.generic.base import BaseListingView
|
||||
from wagtail.admin.views.mixins import SpreadsheetExportMixin
|
||||
|
@ -111,6 +112,9 @@ class DeleteSubmissionsView(TemplateView):
|
|||
|
||||
def get_success_url(self):
|
||||
"""Returns the success URL to redirect to after a successful deletion"""
|
||||
next_url = get_valid_next_url_from_request(self.request)
|
||||
if next_url:
|
||||
return next_url
|
||||
return self.success_url
|
||||
|
||||
def dispatch(self, request, *args, **kwargs):
|
||||
|
@ -140,6 +144,9 @@ class DeleteSubmissionsView(TemplateView):
|
|||
"submissions": self.submissions,
|
||||
}
|
||||
)
|
||||
next_url = get_valid_next_url_from_request(self.request)
|
||||
if next_url:
|
||||
context["next_url"] = next_url
|
||||
|
||||
return context
|
||||
|
||||
|
@ -319,4 +326,5 @@ class SubmissionsListView(SpreadsheetExportMixin, BaseListingView):
|
|||
}
|
||||
)
|
||||
|
||||
context["next_url"] = self.request.get_full_path()
|
||||
return context
|
||||
|
|
Ładowanie…
Reference in New Issue