diff --git a/wagtail/admin/tests/test_pages_views.py b/wagtail/admin/tests/test_pages_views.py index 263d76863..4632a2cea 100644 --- a/wagtail/admin/tests/test_pages_views.py +++ b/wagtail/admin/tests/test_pages_views.py @@ -1118,6 +1118,14 @@ class TestPageEdit(TestCase, WagtailTestUtils): ) self.root_page.add_child(instance=self.event_page) + # Add single event page (to test custom URL routes) + self.single_event_page = SingleEventPage( + title="Mars landing", slug="mars-landing", + location='mars', audience='public', + cost='free', date_from='2001-01-01', + ) + self.root_page.add_child(instance=self.single_event_page) + # Login self.user = self.login() @@ -1803,6 +1811,29 @@ class TestPageEdit(TestCase, WagtailTestUtils): self.assertContains(response, input_field_for_draft_slug, html=True) self.assertNotContains(response, input_field_for_live_slug, html=True) + def test_editor_page_shows_custom_live_url_in_status_when_draft_edits_exist(self): + # When showing a live URL in the status button that differs from the draft one, + # ensure that we pick up any custom URL logic defined on the specific page model + + self.single_event_page.location = "The other side of Mars" + self.single_event_page.slug = "revised-slug-in-draft-only" # live version contains 'hello-world' + self.single_event_page.save_revision() + + response = self.client.get(reverse('wagtailadmin_pages:edit', args=(self.single_event_page.id, ))) + + link_to_draft = 'live + draft' + link_to_live = 'live + draft' + input_field_for_draft_slug = '' + input_field_for_live_slug = '' + + # Status Link should be the live page (not revision) + self.assertContains(response, link_to_live, html=True) + self.assertNotContains(response, link_to_draft, html=True) + + # Editing input for slug should be the draft revision + self.assertContains(response, input_field_for_draft_slug, html=True) + self.assertNotContains(response, input_field_for_live_slug, html=True) + def test_before_edit_page_hook(self): def hook_func(request, page): self.assertIsInstance(request, HttpRequest) diff --git a/wagtail/admin/views/pages.py b/wagtail/admin/views/pages.py index 3240ec485..db78ff7dc 100644 --- a/wagtail/admin/views/pages.py +++ b/wagtail/admin/views/pages.py @@ -499,7 +499,7 @@ def edit(request, page_id): # Page status needs to present the version of the page containing the correct live URL if page.has_unpublished_changes: - page_for_status = latest_revision.page + page_for_status = latest_revision.page.specific else: page_for_status = page