From 223dcbc14dd62c023427028f3d0a78c666a798c9 Mon Sep 17 00:00:00 2001 From: Matt Westcott Date: Sat, 4 Oct 2014 18:11:30 +0200 Subject: [PATCH] make unpublish() a method on PageQuerySet as suggested by @kaedroho in https://github.com/torchbox/wagtail/pull/566#commitcomment-8037361 --- wagtail/wagtailadmin/views/pages.py | 2 +- wagtail/wagtailcore/query.py | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/wagtail/wagtailadmin/views/pages.py b/wagtail/wagtailadmin/views/pages.py index 926dccb96..303c42f33 100644 --- a/wagtail/wagtailadmin/views/pages.py +++ b/wagtail/wagtailadmin/views/pages.py @@ -631,7 +631,7 @@ def copy(request, page_id): # Unpublish copied pages if we need to if not publish_copies: - new_page.get_descendants(inclusive=True).update(live=False, has_unpublished_changes=True) + new_page.get_descendants(inclusive=True).unpublish() # Assign user of this request as the owner of all the new pages new_page.get_descendants(inclusive=True).update(owner=request.user) diff --git a/wagtail/wagtailcore/query.py b/wagtail/wagtailcore/query.py index 0f02fe8aa..cc86d52b7 100644 --- a/wagtail/wagtailcore/query.py +++ b/wagtail/wagtailcore/query.py @@ -198,3 +198,9 @@ class PageQuerySet(MP_NodeQuerySet): """ search_backend = get_search_backend(backend) return search_backend.search(query_string, self, fields=None) + + def unpublish(self): + """ + This unpublishes all pages in the queryset + """ + self.update(live=False, has_unpublished_changes=True)