Added unpublish method to Page

This commit is contained in:
Karl Hobley 2014-08-22 15:12:31 +01:00
parent 5d30efe2c9
commit 67953bccea
3 changed files with 23 additions and 29 deletions

View file

@ -20,7 +20,6 @@ from wagtail.wagtailadmin import tasks, signals
from wagtail.wagtailcore import hooks
from wagtail.wagtailcore.models import Page, PageRevision, get_navigation_menu_items
from wagtail.wagtailcore.signals import page_unpublished
@permission_required('wagtailadmin.access_admin')
@ -364,18 +363,12 @@ def delete(request, page_id):
if request.POST:
if page.live:
# fetch params to pass to the page_unpublished_signal, before the
# deletion happens
specific_class = page.specific_class
specific_page = page.specific
# Unpublish the page
page.unpublish()
parent_id = page.get_parent().id
page.delete()
# If the page is live, send the unpublished signal
if page.live:
page_unpublished.send(sender=specific_class, instance=specific_page)
messages.success(request, _("Page '{0}' deleted.").format(page.title))
for fn in hooks.get_hooks('after_delete_page'):
@ -533,18 +526,11 @@ def unpublish(request, page_id):
raise PermissionDenied
if request.POST:
parent_id = page.get_parent().id
page.live = False
page.save()
# Since page is unpublished clear the approved_go_live_at of all revisions
page.revisions.update(approved_go_live_at=None)
page_unpublished.send(sender=page.specific_class, instance=page.specific)
page.unpublish()
messages.success(request, _("Page '{0}' unpublished.").format(page.title))
return redirect('wagtailadmin_explore', parent_id)
return redirect('wagtailadmin_explore', page.get_parent().id)
return render(request, 'wagtailadmin/pages/confirm_unpublish.html', {
'page': page,

View file

@ -7,7 +7,6 @@ from django.core.management.base import BaseCommand
from django.utils import dateparse, timezone
from wagtail.wagtailcore.models import Page, PageRevision
from wagtail.wagtailcore.signals import page_published, page_unpublished
def revision_date_expired(r):
@ -56,15 +55,11 @@ class Command(BaseCommand):
else:
print("No expired pages to be deactivated found.")
else:
# need to get the list of expired pages before the update,
# so that we can fire the page_unpublished signal on them afterwards
expired_pages_list = list(expired_pages)
expired_pages.update(expired=True, live=False)
# Fire page_unpublished signal for all expired pages
for page in expired_pages_list:
page_unpublished.send(sender=page.specific_class, instance=page.specific)
# Unpublish the expired pages
# Cast to list to make sure the query is fully evaluated
# before unpublishing anything
for page in list(expired_pages):
page.unpublish(set_expired=True)
# 2. get all page revisions for moderation that have been expired
expired_revs = [

View file

@ -31,7 +31,7 @@ from wagtail.utils.deprecation import RemovedInWagtail06Warning
from wagtail.wagtailcore.utils import camelcase_to_underscore
from wagtail.wagtailcore.query import PageQuerySet
from wagtail.wagtailcore.url_routing import RouteResult
from wagtail.wagtailcore.signals import page_published
from wagtail.wagtailcore.signals import page_published, page_unpublished
from wagtail.wagtailsearch import indexed
from wagtail.wagtailsearch.backends import get_search_backend
@ -450,6 +450,19 @@ class Page(six.with_metaclass(PageBase, MP_Node, ClusterableModel, indexed.Index
else:
return self.specific
def unpublish(self, set_expired=False):
if self.live:
self.live = False
if set_expired:
self.expired = True
self.save()
page_unpublished.send(sender=self.specific_class, instance=self.specific)
self.revisions.update(approved_go_live_at=None)
def get_context(self, request, *args, **kwargs):
return {
'self': self,