Пример #1
0
def delete(request, page_id):
    page = get_object_or_404(Page, id=page_id)
    if not page.permissions_for_user(request.user).can_delete():
        raise PermissionDenied

    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

        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'):
            result = fn(request, page)
            if hasattr(result, 'status_code'):
                return result

        return redirect('wagtailadmin_explore', parent_id)

    return render(request, 'wagtailadmin/pages/confirm_delete.html', {
        'page': page,
        'descendant_count': page.get_descendant_count()
    })
Пример #2
0
    def unpublish(self, set_expired=False, commit=True):
        if self.live:
            self.live = False
            self.has_unpublished_changes = True

            if set_expired:
                self.expired = True

            if commit:
                self.save()

            page_unpublished.send(sender=self.specific_class, instance=self.specific)

            self.revisions.update(approved_go_live_at=None)
Пример #3
0
    def unpublish(self, set_expired=False, commit=True):
        if self.live:
            self.live = False
            self.has_unpublished_changes = True

            if set_expired:
                self.expired = True

            if commit:
                self.save()

            page_unpublished.send(sender=self.specific_class, instance=self.specific)

            self.revisions.update(approved_go_live_at=None)
Пример #4
0
def unpublish(request, page_id):
    page = get_object_or_404(Page, id=page_id)
    if not page.permissions_for_user(request.user).can_unpublish():
        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)

        messages.success(request, _("Page '{0}' unpublished.").format(page.title))

        return redirect("wagtailadmin_explore", parent_id)

    return render(request, "wagtailadmin/pages/confirm_unpublish.html", {"page": page})
Пример #5
0
def unpublish(request, page_id):
    page = get_object_or_404(Page, id=page_id)
    if not page.permissions_for_user(request.user).can_unpublish():
        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)

        messages.success(request, _("Page '{0}' unpublished.").format(page.title))

        return redirect('wagtailadmin_explore', parent_id)

    return render(request, 'wagtailadmin/pages/confirm_unpublish.html', {
        'page': page,
    })
Пример #6
0
    def handle(self, *args, **options):
        dryrun = False
        if options['dryrun']:
            print("Will do a dry run.")
            dryrun = True

        # 1. get all expired pages with live = True
        expired_pages = Page.objects.filter(
            live=True,
            expire_at__lt=timezone.now()
        )
        if dryrun:
            if expired_pages:
                print("Expired pages to be deactivated:")
                print("Expiry datetime\t\tSlug\t\tName")
                print("---------------\t\t----\t\t----")
                for ep in expired_pages:
                    print("{0}\t{1}\t{2}".format(
                        ep.expire_at.strftime("%Y-%m-%d %H:%M"),
                        ep.slug,
                        ep.title
                    ))
            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)

        # 2. get all page revisions for moderation that have been expired
        expired_revs = [
            r for r in PageRevision.objects.filter(
                submitted_for_moderation=True
            ) if revision_date_expired(r)
        ]
        if dryrun:
            print("---------------------------------")
            if expired_revs:
                print("Expired revisions to be dropped from moderation queue:")
                print("Expiry datetime\t\tSlug\t\tName")
                print("---------------\t\t----\t\t----")
                for er in expired_revs:
                    rev_data = json.loads(er.content_json)
                    print("{0}\t{1}\t{2}".format(
                        dateparse.parse_datetime(
                            rev_data.get('expire_at')
                        ).strftime("%Y-%m-%d %H:%M"),
                        rev_data.get('slug'),
                        rev_data.get('title')
                    ))
            else:
                print("No expired revision to be dropped from moderation.")
        else:
            for er in expired_revs:
                er.submitted_for_moderation = False
                er.save()

        # 3. get all revisions that need to be published
        revs_for_publishing = PageRevision.objects.filter(
            approved_go_live_at__lt=timezone.now()
        )
        if dryrun:
            print("---------------------------------")
            if revs_for_publishing:
                print("Revisions to be published:")
                print("Go live datetime\t\tSlug\t\tName")
                print("---------------\t\t\t----\t\t----")
                for rp in revs_for_publishing:
                    rev_data = json.loads(rp.content_json)
                    print("{0}\t\t{1}\t{2}".format(
                        rp.approved_go_live_at.strftime("%Y-%m-%d %H:%M"),
                        rev_data.get('slug'),
                        rev_data.get('title')
                    ))
            else:
                print("No pages to go live.")
        else:
            for rp in revs_for_publishing:
                # just run publish for the revision -- since the approved go
                # live datetime is before now it will make the page live
                rp.publish()

                # Fire page_published signal
                page_published.send(sender=rp.page.specific_class, instance=rp.page.specific)
Пример #7
0
    def handle(self, *args, **options):
        dryrun = False
        if options["dryrun"]:
            print("Will do a dry run.")
            dryrun = True

        # 1. get all expired pages with live = True
        expired_pages = Page.objects.filter(live=True, expire_at__lt=timezone.now())
        if dryrun:
            if expired_pages:
                print("Expired pages to be deactivated:")
                print("Expiry datetime\t\tSlug\t\tName")
                print("---------------\t\t----\t\t----")
                for ep in expired_pages:
                    print("{0}\t{1}\t{2}".format(ep.expire_at.strftime("%Y-%m-%d %H:%M"), ep.slug, ep.title))
            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)

        # 2. get all page revisions for moderation that have been expired
        expired_revs = [
            r for r in PageRevision.objects.filter(submitted_for_moderation=True) if revision_date_expired(r)
        ]
        if dryrun:
            print("---------------------------------")
            if expired_revs:
                print("Expired revisions to be dropped from moderation queue:")
                print("Expiry datetime\t\tSlug\t\tName")
                print("---------------\t\t----\t\t----")
                for er in expired_revs:
                    rev_data = json.loads(er.content_json)
                    print(
                        "{0}\t{1}\t{2}".format(
                            dateparse.parse_datetime(rev_data.get("expire_at")).strftime("%Y-%m-%d %H:%M"),
                            rev_data.get("slug"),
                            rev_data.get("title"),
                        )
                    )
            else:
                print("No expired revision to be dropped from moderation.")
        else:
            for er in expired_revs:
                er.submitted_for_moderation = False
                er.save()

        # 3. get all revisions that need to be published
        revs_for_publishing = PageRevision.objects.filter(approved_go_live_at__lt=timezone.now())
        if dryrun:
            print("---------------------------------")
            if revs_for_publishing:
                print("Revisions to be published:")
                print("Go live datetime\t\tSlug\t\tName")
                print("---------------\t\t\t----\t\t----")
                for rp in revs_for_publishing:
                    rev_data = json.loads(rp.content_json)
                    print(
                        "{0}\t\t{1}\t{2}".format(
                            rp.approved_go_live_at.strftime("%Y-%m-%d %H:%M"),
                            rev_data.get("slug"),
                            rev_data.get("title"),
                        )
                    )
            else:
                print("No pages to go live.")
        else:
            for rp in revs_for_publishing:
                # just run publish for the revision -- since the approved go
                # live datetime is before now it will make the page live
                rp.publish()

                # Fire page_published signal
                page_published.send(sender=rp.page.specific_class, instance=rp.page.specific)