0
0
mirror of https://github.com/wagtail/wagtail.git synced 2024-11-30 11:10:43 +01:00

Publish latest revision when bulk publishing

Fixes #7690
This commit is contained in:
Matt Westcott 2022-01-04 17:22:38 +00:00 committed by Matt Westcott
parent 731cc540b0
commit bd1fbb09ea
2 changed files with 27 additions and 9 deletions

View File

@ -28,6 +28,10 @@ class TestBulkPublish(TestCase, WagtailTestUtils):
for child_page in self.child_pages:
self.root_page.add_child(instance=child_page)
for i, child_page in enumerate(self.child_pages):
child_page.content = f"Hello updated world {i}!"
child_page.save_revision()
self.url = reverse('wagtail_bulk_action', args=('wagtailcore', 'page', 'publish', )) + '?'
for child_page in self.pages_to_be_published:
self.url += f'id={child_page.id}&'
@ -96,7 +100,9 @@ class TestBulkPublish(TestCase, WagtailTestUtils):
# Check that the child pages were published
for child_page in self.pages_to_be_published:
self.assertTrue(Page.objects.get(id=child_page.id).live)
published_page = SimplePage.objects.get(id=child_page.id)
self.assertTrue(published_page.live)
self.assertIn("Hello updated", published_page.content)
# Check that the child pages not to be published remain
for child_page in self.pages_not_to_be_published:
@ -178,6 +184,10 @@ class TestBulkPublishIncludingDescendants(TestCase, WagtailTestUtils):
for child_page in self.child_pages:
self.root_page.add_child(instance=child_page)
for i, child_page in enumerate(self.child_pages):
child_page.content = f"Hello updated world {i}!"
child_page.save_revision()
# map of the form { page: [child_pages] } to be added
self.grandchildren_pages = {
self.pages_to_be_published[0]: [
@ -191,6 +201,11 @@ class TestBulkPublishIncludingDescendants(TestCase, WagtailTestUtils):
for grandchild_page in grandchild_pages:
child_page.add_child(instance=grandchild_page)
for child_page, grandchild_pages in self.grandchildren_pages.items():
for grandchild_page in grandchild_pages:
grandchild_page.content = grandchild_page.content.replace("Hello world", "Hello grandchild")
grandchild_page.save_revision()
self.url = reverse('wagtail_bulk_action', args=('wagtailcore', 'page', 'publish', )) + '?'
for child_page in self.pages_to_be_published:
self.url += f'&id={child_page.id}'
@ -222,7 +237,9 @@ class TestBulkPublishIncludingDescendants(TestCase, WagtailTestUtils):
# Check that the child pages were published
for child_page in self.pages_to_be_published:
self.assertTrue(Page.objects.get(id=child_page.id).live)
published_child_page = SimplePage.objects.get(id=child_page.id)
self.assertTrue(published_child_page.live)
self.assertIn("Hello updated", published_child_page.content)
# Check that the child pages not to be published remain
for child_page in self.pages_not_to_be_published:
@ -230,7 +247,9 @@ class TestBulkPublishIncludingDescendants(TestCase, WagtailTestUtils):
for grandchild_pages in self.grandchildren_pages.values():
for grandchild_page in grandchild_pages:
self.assertTrue(Page.objects.get(id=grandchild_page.id).live)
published_grandchild_page = SimplePage.objects.get(id=grandchild_page.id)
self.assertTrue(published_grandchild_page.live)
self.assertIn("Hello grandchild", published_grandchild_page.content)
def test_publish_not_include_children_view_post(self):
"""
@ -244,7 +263,9 @@ class TestBulkPublishIncludingDescendants(TestCase, WagtailTestUtils):
# Check that the child pages were published
for child_page in self.pages_to_be_published:
self.assertTrue(Page.objects.get(id=child_page.id).live)
published_child_page = SimplePage.objects.get(id=child_page.id)
self.assertTrue(published_child_page.live)
self.assertIn("Hello updated", published_child_page.content)
# Check that the descendant pages were not published
for grandchild_pages in self.grandchildren_pages.values():

View File

@ -34,16 +34,13 @@ class PublishBulkAction(PageBulkAction):
def execute_action(cls, objects, include_descendants=False, user=None, **kwargs):
num_parent_objects, num_child_objects = 0, 0
for page in objects:
page = page.specific
revision = page.save_revision(user=user)
revision.publish(user=user)
page.get_latest_revision().publish(user=user)
num_parent_objects += 1
if include_descendants:
for draft_descendant_page in page.get_descendants().not_live().defer_streamfields().specific():
if user is None or draft_descendant_page.permissions_for_user(user).can_publish():
revision = draft_descendant_page.save_revision(user=user)
revision.publish(user=user)
draft_descendant_page.get_latest_revision().publish(user=user)
num_child_objects += 1
return num_parent_objects, num_child_objects