0
0
mirror of https://github.com/wagtail/wagtail.git synced 2024-11-29 17:36:49 +01:00

Fix regression in #3988 where no revision records exist - fixes #4505

This commit is contained in:
Matt Westcott 2018-05-04 17:28:41 +01:00 committed by Matt Westcott
parent 7f38c476be
commit cd3b676c44
2 changed files with 20 additions and 5 deletions

View File

@ -1225,6 +1225,15 @@ class TestPageEdit(TestCase, WagtailTestUtils):
)
self.root_page.add_child(instance=self.single_event_page)
self.unpublished_page = SimplePage(
title="Hello unpublished world!",
slug="hello-unpublished-world",
content="hello",
live=False,
has_unpublished_changes=True,
)
self.root_page.add_child(instance=self.unpublished_page)
# Login
self.user = self.login()
@ -1237,6 +1246,11 @@ class TestPageEdit(TestCase, WagtailTestUtils):
self.assertContains(response, '<legend>Speaker lineup</legend>')
self.assertContains(response, 'Add speakers')
def test_edit_draft_page_with_no_revisions(self):
# Tests that the edit page loads
response = self.client.get(reverse('wagtailadmin_pages:edit', args=(self.unpublished_page.id, )))
self.assertEqual(response.status_code, 200)
def test_edit_multipart(self):
"""
Test checks if 'enctype="multipart/form-data"' is added and only to forms that require multipart encoding.

View File

@ -308,8 +308,9 @@ def create(request, content_type_app_name, content_type_model_name, parent_page_
def edit(request, page_id):
latest_revision = get_object_or_404(Page, id=page_id).get_latest_revision()
page = get_object_or_404(Page, id=page_id).get_latest_revision_as_page()
real_page_record = get_object_or_404(Page, id=page_id)
latest_revision = real_page_record.get_latest_revision()
page = real_page_record.get_latest_revision_as_page()
parent = page.get_parent()
content_type = ContentType.objects.get_for_model(page)
@ -515,9 +516,9 @@ def edit(request, page_id):
messages.warning(request, _("This page is currently awaiting moderation"), buttons=buttons)
# 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.specific
if page.live and page.has_unpublished_changes:
# Page status needs to present the version of the page containing the correct live URL
page_for_status = real_page_record.specific
else:
page_for_status = page