0
0
mirror of https://github.com/wagtail/wagtail.git synced 2024-12-01 11:41:20 +01:00

(FIX): Page Copy does not trigger page_published signal (#6434)

This commit is contained in:
samgans 2020-10-06 17:02:26 +03:00 committed by GitHub
parent bcf1fab77f
commit bff6766360
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 60 additions and 0 deletions

View File

@ -1866,6 +1866,12 @@ class Page(AbstractPage, index.Indexed, ClusterableModel, metaclass=PageBase):
page_copy.first_published_at = latest_revision_as_page_revision.created_at
page_copy.save(clean=False)
if page_copy.live:
page_published.send(
sender=page_copy.specific_class, instance=page_copy,
revision=latest_revision_as_page_revision
)
# Log
if log_action:
parent = specific_self.get_parent()

View File

@ -17,6 +17,7 @@ from freezegun import freeze_time
from wagtail.core.models import (
Locale, Page, PageManager, ParentNotTranslatedError, Site, get_page_models, get_translatable_models)
from wagtail.core.signals import page_published
from wagtail.tests.testapp.models import (
AbstractPage, Advert, AlwaysShowInMenusPage, BlogCategory, BlogCategoryBlogPage, BusinessChild,
BusinessIndex, BusinessNowherePage, BusinessSubIndex, CustomManager, CustomManagerPage,
@ -1490,6 +1491,59 @@ class TestCopyPage(TestCase):
with self.assertRaises(RuntimeError):
new_page.copy()
def test_copy_published_emits_signal(self):
"""Test that copying of a published page emits a page_published signal."""
christmas_page = EventPage.objects.get(url_path='/home/events/christmas/')
signal_fired = False
signal_page = None
def page_published_handler(sender, instance, **kwargs):
nonlocal signal_fired
nonlocal signal_page
signal_fired = True
signal_page = instance
page_published.connect(page_published_handler)
copy_page = christmas_page.copy(
update_attrs={'title': "New christmas", 'slug': 'new-christmas'},
)
self.assertTrue(signal_fired)
self.assertEqual(signal_page, copy_page)
def test_copy_unpublished_not_emits_signal(self):
"""Test that copying of an unpublished page not emits a page_published signal."""
homepage = Page.objects.get(url_path='/home/')
homepage.live = False
homepage.save()
signal_fired = False
def page_published_handler(sender, instance, **kwargs):
nonlocal signal_fired
signal_fired = True
page_published.connect(page_published_handler)
homepage.copy(update_attrs={'slug': 'new_slug'})
self.assertFalse(signal_fired)
def test_copy_keep_live_false_not_emits_signal(self):
"""Test that copying of a live page with keep_live=False not emits a page_published signal."""
homepage = Page.objects.get(url_path='/home/')
signal_fired = False
def page_published_handler(sender, instance, **kwargs):
nonlocal signal_fired
signal_fired = True
page_published.connect(page_published_handler)
homepage.copy(
keep_live=False,
update_attrs={'slug': 'new_slug'}
)
self.assertFalse(signal_fired)
class TestCopyForTranslation(TestCase):
fixtures = ['test.json']