From bd226fcedf738f9349d234cc9ca662a33841230f Mon Sep 17 00:00:00 2001 From: Chris Darko Date: Thu, 21 Jul 2016 16:36:28 +1000 Subject: [PATCH] Fix use of Page instead of specific_class Uses specific_class.url instead of Page.url for getting the 'view_live' URL in the success message following Page publication. --- CHANGELOG.txt | 1 + CONTRIBUTORS.rst | 1 + docs/releases/1.6.rst | 1 + .../wagtailadmin/tests/test_pages_views.py | 54 +++++++++++++++++++ wagtail/wagtailadmin/views/pages.py | 2 +- 5 files changed, 58 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 277c4ac23..ef680213e 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -25,6 +25,7 @@ Changelog * Page previews now pass additional HTTP headers, to simulate the page being viewed by the logged-in user and avoid clashes with middleware (Robert Rollins) * Added back buttons to page delete and unpublish confirmation screens (Matt Westcott) * Recognise Flickr embed URLs using HTTPS (Danielle Madeley) + * Success message when publishing a page now correctly respects custom URLs defined on the specific page class (Chris Darko) * Fix: Email templates and document uploader now support custom `STATICFILES_STORAGE` (Jonny Scholes) * Fix: Removed alignment options (deprecated in HTML and not rendered by Wagtail) from `TableBlock` context menu (Moritz Pfeiffer) * Fix: Fixed incorrect CSS path on ModelAdmin's "choose a parent page" view diff --git a/CONTRIBUTORS.rst b/CONTRIBUTORS.rst index 2a5e496dd..d3f7e7ee6 100644 --- a/CONTRIBUTORS.rst +++ b/CONTRIBUTORS.rst @@ -153,6 +153,7 @@ Contributors * Tim Graham * Thibaud Colas * Tobias Schmidt +* Chris Darko Translators =========== diff --git a/docs/releases/1.6.rst b/docs/releases/1.6.rst index afdf6f02d..84d53d427 100644 --- a/docs/releases/1.6.rst +++ b/docs/releases/1.6.rst @@ -50,6 +50,7 @@ Minor features * Page previews now pass additional HTTP headers, to simulate the page being viewed by the logged-in user and avoid clashes with middleware (Robert Rollins) * Added back buttons to page delete and unpublish confirmation screens (Matt Westcott) * Recognise Flickr embed URLs using HTTPS (Danielle Madeley) + * Success message when publishing a page now correctly respects custom URLs defined on the specific page class (Chris Darko) Bug fixes diff --git a/wagtail/wagtailadmin/tests/test_pages_views.py b/wagtail/wagtailadmin/tests/test_pages_views.py index 63a9405ec..8674fceaa 100644 --- a/wagtail/wagtailadmin/tests/test_pages_views.py +++ b/wagtail/wagtailadmin/tests/test_pages_views.py @@ -19,6 +19,7 @@ from django.utils import formats, timezone from django.utils.dateparse import parse_date from wagtail.tests.testapp.models import ( + EVENT_AUDIENCE_CHOICES, Advert, AdvertPlacement, BusinessChild, BusinessIndex, BusinessSubIndex, EventPage, EventPageCarouselItem, FilePage, SimplePage, SingleEventPage, StandardChild, StandardIndex, TaggedPage) @@ -3027,6 +3028,59 @@ class TestIssue2599(TestCase, WagtailTestUtils): self.assertEqual(response.context['self'].get_parent(), homepage) +class TestIssue2492(TestCase, WagtailTestUtils): + """ + The publication submission message generation was performed using + the Page class, as opposed to the specific_class for that Page. + This test ensures that the specific_class url method is called + when the 'view live' message button is created. + """ + def setUp(self): + self.root_page = Page.objects.get(id=2) + child_page = SingleEventPage( + title="Test Event", slug="test-event", location="test location", + cost="10", date_from=datetime.datetime.now(), + audience=EVENT_AUDIENCE_CHOICES[0][0]) + self.root_page.add_child(instance=child_page) + child_page.save_revision().publish() + self.child_page = SingleEventPage.objects.get(id=child_page.id) + self.user = self.login() + + def test_page_edit_post_publish_url(self): + post_data = { + 'action-publish': "Publish", + 'title': self.child_page.title, + 'date_from': self.child_page.date_from, + 'slug': self.child_page.slug, + 'audience': self.child_page.audience, + 'location': self.child_page.location, + 'cost': self.child_page.cost, + 'carousel_items-TOTAL_FORMS': 0, + 'carousel_items-INITIAL_FORMS': 0, + 'carousel_items-MIN_NUM_FORMS': 0, + 'carousel_items-MAX_NUM_FORMS': 0, + 'speakers-TOTAL_FORMS': 0, + 'speakers-INITIAL_FORMS': 0, + 'speakers-MIN_NUM_FORMS': 0, + 'speakers-MAX_NUM_FORMS': 0, + 'related_links-TOTAL_FORMS': 0, + 'related_links-INITIAL_FORMS': 0, + 'related_links-MIN_NUM_FORMS': 0, + 'related_links-MAX_NUM_FORMS': 0, + } + response = self.client.post( + reverse('wagtailadmin_pages:edit', args=(self.child_page.id, )), + post_data, follow=True) + + # Grab a fresh copy's URL + new_url = SingleEventPage.objects.get(id=self.child_page.id).url + + # The "View Live" button should have the custom URL. + for message in response.context['messages']: + self.assertIn('"{}"'.format(new_url), message.message) + break + + class TestInlinePanelMedia(TestCase, WagtailTestUtils): """ Test that form media required by InlinePanels is correctly pulled in to the edit page diff --git a/wagtail/wagtailadmin/views/pages.py b/wagtail/wagtailadmin/views/pages.py index 1f2e76208..5c71797e5 100644 --- a/wagtail/wagtailadmin/views/pages.py +++ b/wagtail/wagtailadmin/views/pages.py @@ -316,7 +316,7 @@ def edit(request, page_id): revision.publish() # Need to reload the page because the URL may have changed, and we # need the up-to-date URL for the "View Live" button. - page = Page.objects.get(pk=page.pk) + page = page.specific_class.objects.get(pk=page.pk) # Notifications if is_publishing: