mirror of
https://github.com/Hopiu/wagtail.git
synced 2026-05-11 00:33:17 +00:00
Merge branch 'publish-signal' into varnish-cache-invalidation
This commit is contained in:
commit
71f0ff6506
3 changed files with 56 additions and 3 deletions
|
|
@ -7,6 +7,7 @@ from django.core.paginator import Paginator
|
|||
from wagtail.tests.models import SimplePage, EventPage, StandardIndex, StandardChild, BusinessIndex, BusinessChild, BusinessSubIndex
|
||||
from wagtail.tests.utils import unittest, WagtailTestUtils
|
||||
from wagtail.wagtailcore.models import Page, PageRevision
|
||||
from wagtail.wagtailcore.signals import page_published
|
||||
from wagtail.wagtailusers.models import UserProfile
|
||||
|
||||
|
||||
|
|
@ -170,6 +171,15 @@ class TestPageCreation(TestCase, WagtailTestUtils):
|
|||
self.assertFalse(page.live)
|
||||
|
||||
def test_create_simplepage_post_publish(self):
|
||||
# Connect a mock signal handler to page_published signal
|
||||
signal_fired = [False]
|
||||
signal_page = [None]
|
||||
def page_published_handler(sender, instance, **kwargs):
|
||||
signal_fired[0] = True
|
||||
signal_page[0] = instance
|
||||
page_published.connect(page_published_handler)
|
||||
|
||||
# Post
|
||||
post_data = {
|
||||
'title': "New page!",
|
||||
'content': "Some content",
|
||||
|
|
@ -187,6 +197,11 @@ class TestPageCreation(TestCase, WagtailTestUtils):
|
|||
self.assertIsInstance(page, SimplePage)
|
||||
self.assertTrue(page.live)
|
||||
|
||||
# Check that the page_published signal was fired
|
||||
self.assertTrue(signal_fired[0])
|
||||
self.assertEqual(signal_page[0], page)
|
||||
self.assertEqual(signal_page[0], signal_page[0].specific)
|
||||
|
||||
def test_create_simplepage_post_submit(self):
|
||||
# Create a moderator user for testing email
|
||||
moderator = User.objects.create_superuser('moderator', 'moderator@email.com', 'password')
|
||||
|
|
@ -245,7 +260,6 @@ class TestPageCreation(TestCase, WagtailTestUtils):
|
|||
response = self.client.get(reverse('wagtailadmin_pages_create', args=('tests', 'simplepage', 100000)))
|
||||
self.assertEqual(response.status_code, 404)
|
||||
|
||||
@unittest.expectedFailure # FIXME: Crashes!
|
||||
def test_create_nonpagetype(self):
|
||||
response = self.client.get(reverse('wagtailadmin_pages_create', args=('wagtailimages', 'image', self.root_page.id)))
|
||||
self.assertEqual(response.status_code, 404)
|
||||
|
|
@ -328,6 +342,14 @@ class TestPageEdit(TestCase, WagtailTestUtils):
|
|||
self.assertTrue(child_page_new.has_unpublished_changes)
|
||||
|
||||
def test_page_edit_post_publish(self):
|
||||
# Connect a mock signal handler to page_published signal
|
||||
signal_fired = [False]
|
||||
signal_page = [None]
|
||||
def page_published_handler(sender, instance, **kwargs):
|
||||
signal_fired[0] = True
|
||||
signal_page[0] = instance
|
||||
page_published.connect(page_published_handler)
|
||||
|
||||
# Tests publish from edit page
|
||||
post_data = {
|
||||
'title': "I've been edited!",
|
||||
|
|
@ -344,6 +366,11 @@ class TestPageEdit(TestCase, WagtailTestUtils):
|
|||
child_page_new = SimplePage.objects.get(id=self.child_page.id)
|
||||
self.assertEqual(child_page_new.title, post_data['title'])
|
||||
|
||||
# Check that the page_published signal was fired
|
||||
self.assertTrue(signal_fired[0])
|
||||
self.assertEqual(signal_page[0], child_page_new)
|
||||
self.assertEqual(signal_page[0], signal_page[0].specific)
|
||||
|
||||
# The page shouldn't have "has_unpublished_changes" flag set
|
||||
self.assertFalse(child_page_new.has_unpublished_changes)
|
||||
|
||||
|
|
@ -642,6 +669,14 @@ class TestApproveRejectModeration(TestCase, WagtailTestUtils):
|
|||
"""
|
||||
This posts to the approve moderation view and checks that the page was approved
|
||||
"""
|
||||
# Connect a mock signal handler to page_published signal
|
||||
signal_fired = [False]
|
||||
signal_page = [None]
|
||||
def page_published_handler(sender, instance, **kwargs):
|
||||
signal_fired[0] = True
|
||||
signal_page[0] = instance
|
||||
page_published.connect(page_published_handler)
|
||||
|
||||
# Post
|
||||
response = self.client.post(reverse('wagtailadmin_pages_approve_moderation', args=(self.revision.id, )), {
|
||||
'foo': "Must post something or the view won't see this as a POST request",
|
||||
|
|
@ -653,6 +688,11 @@ class TestApproveRejectModeration(TestCase, WagtailTestUtils):
|
|||
# Page must be live
|
||||
self.assertTrue(Page.objects.get(id=self.page.id).live)
|
||||
|
||||
# Check that the page_published signal was fired
|
||||
self.assertTrue(signal_fired[0])
|
||||
self.assertEqual(signal_page[0], self.page)
|
||||
self.assertEqual(signal_page[0], signal_page[0].specific)
|
||||
|
||||
def test_approve_moderation_view_bad_revision_id(self):
|
||||
"""
|
||||
This tests that the approve moderation view handles invalid revision ids correctly
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ from wagtail.wagtailadmin.forms import SearchForm
|
|||
from wagtail.wagtailadmin import tasks, hooks, signals
|
||||
|
||||
from wagtail.wagtailcore.models import Page, PageRevision
|
||||
from wagtail.wagtailcore.signals import page_published
|
||||
|
||||
|
||||
@permission_required('wagtailadmin.access_admin')
|
||||
|
|
@ -115,12 +116,17 @@ def create(request, content_type_app_name, content_type_model_name, parent_page_
|
|||
except ContentType.DoesNotExist:
|
||||
raise Http404
|
||||
|
||||
# Get class
|
||||
page_class = content_type.model_class()
|
||||
|
||||
# Make sure the class is a descendant of Page
|
||||
if not issubclass(page_class, Page):
|
||||
raise Http404
|
||||
|
||||
# page must be in the list of allowed subpage types for this parent ID
|
||||
if content_type not in parent_page.clean_subpage_types():
|
||||
raise PermissionDenied
|
||||
|
||||
page_class = content_type.model_class()
|
||||
|
||||
page = page_class(owner=request.user)
|
||||
edit_handler_class = get_page_edit_handler(page_class)
|
||||
form_class = edit_handler_class.get_form_class(page_class)
|
||||
|
|
@ -153,6 +159,7 @@ def create(request, content_type_app_name, content_type_model_name, parent_page_
|
|||
page.save_revision(user=request.user, submitted_for_moderation=is_submitting)
|
||||
|
||||
if is_publishing:
|
||||
page_published.send(sender=page_class, instance=page)
|
||||
messages.success(request, _("Page '{0}' published.").format(page.title))
|
||||
elif is_submitting:
|
||||
messages.success(request, _("Page '{0}' submitted for moderation.").format(page.title))
|
||||
|
|
@ -233,6 +240,7 @@ def edit(request, page_id):
|
|||
page.save_revision(user=request.user, submitted_for_moderation=is_submitting)
|
||||
|
||||
if is_publishing:
|
||||
page_published.send(sender=page.__class__, instance=page)
|
||||
messages.success(request, _("Page '{0}' published.").format(page.title))
|
||||
elif is_submitting:
|
||||
messages.success(request, _("Page '{0}' submitted for moderation.").format(page.title))
|
||||
|
|
@ -601,6 +609,7 @@ def approve_moderation(request, revision_id):
|
|||
|
||||
if request.POST:
|
||||
revision.publish()
|
||||
page_published.send(sender=revision.page.__class__, instance=revision.page.specific)
|
||||
messages.success(request, _("Page '{0}' published.").format(revision.page.title))
|
||||
tasks.send_notification.delay(revision.id, 'approved', request.user.id)
|
||||
|
||||
|
|
|
|||
4
wagtail/wagtailcore/signals.py
Normal file
4
wagtail/wagtailcore/signals.py
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
from django.dispatch import Signal
|
||||
|
||||
|
||||
page_published = Signal(providing_args=['instance'])
|
||||
Loading…
Reference in a new issue