Call Page.unpublish() on each page when unpublishing queryset

pull/1973/merge
Matt Westcott 2015-11-18 15:43:22 +00:00 zatwierdzone przez Karl Hobley
rodzic e09a56f51c
commit 78ba194f48
2 zmienionych plików z 33 dodań i 3 usunięć

Wyświetl plik

@ -230,9 +230,10 @@ class PageQuerySet(SearchableQuerySetMixin, TreeQuerySet):
def unpublish(self):
"""
This unpublishes all pages in the QuerySet.
This unpublishes all live pages in the QuerySet.
"""
self.update(live=False, has_unpublished_changes=True)
for page in self.live():
page.unpublish()
def specific(self):
"""

Wyświetl plik

@ -1,7 +1,8 @@
from django.test import TestCase
from wagtail.wagtailcore.models import Page, PageViewRestriction
from wagtail.tests.testapp.models import EventPage
from wagtail.wagtailcore.signals import page_unpublished
from wagtail.tests.testapp.models import EventPage, SingleEventPage
class TestPageQuerySet(TestCase):
@ -434,6 +435,34 @@ class TestPageQuerySetSearch(TestCase):
Page.objects.get(url_path='/home/events/someone-elses-event/').specific,
])
def test_unpublish(self):
# set up a listener for the unpublish signal
unpublish_signals_fired = []
def page_unpublished_handler(sender, instance, **kwargs):
unpublish_signals_fired.append((sender, instance))
page_unpublished.connect(page_unpublished_handler)
events_index = Page.objects.get(url_path='/home/events/')
events_index.get_children().unpublish()
# Previously-live children of event index should now be non-live
christmas = EventPage.objects.get(url_path='/home/events/christmas/')
saint_patrick = SingleEventPage.objects.get(url_path='/home/events/saint-patrick/')
unpublished_event = EventPage.objects.get(url_path='/home/events/tentative-unpublished-event/')
self.assertFalse(christmas.live)
self.assertFalse(saint_patrick.live)
# Check that a signal was fired for each unpublished page
self.assertIn((EventPage, christmas), unpublish_signals_fired)
self.assertIn((SingleEventPage, saint_patrick), unpublish_signals_fired)
# a signal should not be fired for pages that were in the queryset
# but already unpublished
self.assertNotIn((EventPage, unpublished_event), unpublish_signals_fired)
class TestSpecificQuery(TestCase):
"""