From fab11259bc9116651be7bf4640c71124d7366be3 Mon Sep 17 00:00:00 2001 From: Robert Rollins Date: Fri, 16 Dec 2016 17:26:53 -0800 Subject: [PATCH] Maintain the 'next' GET argument through the add_subpage workflow. Every other Page workflow seems to maintain this argument, to ensure that the user ends up back at the page they were on when they started. This patch enables the add_subpage workflow to do the same. --- CHANGELOG.txt | 1 + docs/releases/1.9.rst | 1 + .../templates/wagtailadmin/pages/add_subpage.html | 2 +- wagtail/wagtailadmin/tests/test_pages_views.py | 13 +++++++++++++ wagtail/wagtailadmin/views/pages.py | 1 + 5 files changed, 17 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 4e77d79ab6..7789ced099 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -9,6 +9,7 @@ Changelog * Added `before_copy_page` and `after_copy_page` hooks (Matheus Bratfisch) * View live / draft links in the admin now consistently open in a new window (Marco Fucci) * `ChoiceBlock` now omits the blank option if the block is required and has a default value (Andreas Nüßlein) + * The `add_subpage` view now maintains a `next` URL parameter to specify where to redirect to after completing page creation (Robert Rollins) * Fix: Help text for StreamField is now visible and does not cover block controls (Stein Strindhaug) * Fix: "X minutes ago" timestamps are now marked for translation (Janneke Janssen, Matt Westcott) diff --git a/docs/releases/1.9.rst b/docs/releases/1.9.rst index 9c9802317c..b1d0a7b657 100644 --- a/docs/releases/1.9.rst +++ b/docs/releases/1.9.rst @@ -28,6 +28,7 @@ Other features * Added :ref:`before_copy_page` and :ref:`after_copy_page` hooks (Matheus Bratfisch) * View live / draft links in the admin now consistently open in a new window (Marco Fucci) * ``ChoiceBlock`` now omits the blank option if the block is required and has a default value (Andreas Nüßlein) + * The ``add_subpage`` view now maintains a ``next`` URL parameter to specify where to redirect to after completing page creation (Robert Rollins) Bug fixes diff --git a/wagtail/wagtailadmin/templates/wagtailadmin/pages/add_subpage.html b/wagtail/wagtailadmin/templates/wagtailadmin/pages/add_subpage.html index e223cd66ff..0104c929c1 100644 --- a/wagtail/wagtailadmin/templates/wagtailadmin/pages/add_subpage.html +++ b/wagtail/wagtailadmin/templates/wagtailadmin/pages/add_subpage.html @@ -17,7 +17,7 @@
  • diff --git a/wagtail/wagtailadmin/tests/test_pages_views.py b/wagtail/wagtailadmin/tests/test_pages_views.py index b3ff6acf51..e9cd029b73 100644 --- a/wagtail/wagtailadmin/tests/test_pages_views.py +++ b/wagtail/wagtailadmin/tests/test_pages_views.py @@ -421,6 +421,8 @@ class TestPageCreation(TestCase, WagtailTestUtils): self.assertEqual(response.status_code, 200) self.assertContains(response, "Simple page") + target_url = reverse('wagtailadmin_pages:add', args=('tests', 'simplepage', self.root_page.id)) + self.assertContains(response, 'href="%s"' % target_url) # List of available page types should not contain pages with is_creatable = False self.assertNotContains(response, "MTI base page") # List of available page types should not contain abstract pages @@ -481,6 +483,17 @@ class TestPageCreation(TestCase, WagtailTestUtils): response = self.client.get(reverse('wagtailadmin_pages:add_subpage', args=(100000, ))) self.assertEqual(response.status_code, 404) + def test_add_subpage_with_next_param(self): + response = self.client.get( + reverse('wagtailadmin_pages:add_subpage', args=(self.root_page.id, )), + {'next': '/admin/users/'} + ) + self.assertEqual(response.status_code, 200) + + self.assertContains(response, "Simple page") + target_url = reverse('wagtailadmin_pages:add', args=('tests', 'simplepage', self.root_page.id)) + self.assertContains(response, 'href="%s?next=/admin/users/"' % target_url) + def test_create_simplepage(self): response = self.client.get(reverse('wagtailadmin_pages:add', args=('tests', 'simplepage', self.root_page.id))) self.assertEqual(response.status_code, 200) diff --git a/wagtail/wagtailadmin/views/pages.py b/wagtail/wagtailadmin/views/pages.py index 9f0ff21c12..c2809e0607 100644 --- a/wagtail/wagtailadmin/views/pages.py +++ b/wagtail/wagtailadmin/views/pages.py @@ -127,6 +127,7 @@ def add_subpage(request, parent_page_id): return render(request, 'wagtailadmin/pages/add_subpage.html', { 'parent_page': parent_page, 'page_types': page_types, + 'next': get_valid_next_url_from_request(request), })