Skip to main content

Run tests, lint and publish PyPI version

wagtail trash

Instead of deleting pages when pressing delete, pages will get thrown into the "Trash Can".

Install

  1. First install the python package: pip install wagtail-trash

This step will install both wagtail-trash and wagtail-modeladmin which is a requirement for the admin.

  1. Then add both wagtail-trash and wagtail-modeladmin to your INSTALLED_APPS:
INSTALLED_APPS = [
    # ...
    "wagtail_modeladmin",
    "wagtail_trash",
]
  1. Run migrations, et voila!

How it works

Wagtail Trash works by hooking into the Wagtail hook before_delete_page and overriding the delete view. Instead of deleting the page the page gets moved to the special "Trash" page. The deleted page and all descendants will get unpublished. From the trash can in Wagtail admin it's then possible to permanently delete the page or to restore the page. Restoring a page will also republish the pages that were published when getting deleted. If the parent of the deleted page is either in the trash can or permanently deleted it's still possible to restore the pages by supplying an alternate parent.

Usage

App order

Since Wagtail Trash uses the hook before_delete_page it might interfere with your applications before_delete_page if you have defined one that returns a status code. Make sure wagtail trash is the last hook that runs otherwise or your custom before_delete_page might not run since Wagtail Trash doesn't call it.

# Example
INSTALLED_APPS = [
    "wagtail.sites",
    "wagtail",
    "wagtail.contrib.forms",
    "wagtail.contrib.redirects",
    "wagtail_modeladmin",
    "wagtail.contrib.routable_page",
    "wagtail.contrib.settings",
    "wagtail_trash",  # Import here
    ...
]

Page manager

Also, Wagtail Trash "deletes" pages by unpublishing them, so if you use a queryset that doesn't filter out unpublished pages, pages in trash can might show up. There is a manager that will fix this for you included, example:

from wagtail.models import Page, PageManager
from wagtail_trash.managers import TrashManager

class SomePage(Page):
    objects = PageManager()  # needed, so _default_manager isn't the trash manager
    objects_excluding_trash = TrashManager()

# Now you can do this without getting any pages from the bin:
SomePage.objects_excluding_trash.all()

Exclude from sitemap

Add SkipSitemapIfInTrashMixin if you want trashed pages to be excluded from sitemap.

from wagtail.models import Page
from wagtail_trash.mixins import SkipSitemapIfInTrashMixin

class SomePage(SkipSitemapIfInTrashMixin, Page):
    ...

Permissions

If you remove a page under a restricted area, this page will be moved and therefore get new permissions. A user might go from not being allowed to see pages under e.g. "Secret Page", but when a page under this area is moved to trash can, the permissions from "Secret Page" are gone so now the user will see it in the trash can. This is a solvable issue and will be fixed in a later version.

Clearing the bin regularly

There is an included managment-command called empty_trash that takes a required argument --older_than_days. To remove all items in the bin that's been there more than 30 days run this command:

./manage.py empty_trash --older_than_days=30

Git flow

This project uses git flow, current release is in the main branch and the current development is in the develop branch.

License

wagtail trash is released under the MIT License.

Metadata

Release files for wagtail-trash 3.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for wagtail-trash 3.2.0
File Size Uploaded Provenance Actions
wagtail_trash-3.2.0.tar.gz 19.9 kB Without provenance Details for wagtail_trash-3.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for wagtail-trash 3.2.0
File Interpreter ABI Platform Actions
wagtail_trash-3.2.0-py3-none-any.whl Python 3 none any Details for wagtail_trash-3.2.0-py3-none-any.whl

Total release size: 42.7 kB

Release files / wagtail_trash-3.2.0.tar.gz

Download URL wagtail_trash-3.2.0.tar.gz
Size 19.9 kB
Tags Source
SHA-256 checksum
How to use checksums
3644aa27ba905690d63972a6c7ddee2e363d535fdb723b6ca497918d68c9e733
BLAKE2b-256 checksum
How to use checksums
de9998398332ca235e919e09379982b8d71cbdd5043f8ca2131c9a58c9cf4f06
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release files / wagtail_trash-3.2.0-py3-none-any.whl

Download URL wagtail_trash-3.2.0-py3-none-any.whl
Size 22.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
761c876db6134719c738e0f7533f8f3fb9697b6c9e080311d8722edeb0b75fe4
BLAKE2b-256 checksum
How to use checksums
71bb219e4f8676824afa46d0a09a3cc7d30550a8a838d45df6c0ce9dcb1744a5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Security for wagtail-trash 3.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page