Skip to main content

Make deleted pages only temporarily deleted.

Project description

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.

Caveats

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.

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.core.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()

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

wagtail-trash-3.0.0.tar.gz (18.8 kB view details)

Uploaded Source

Built Distribution

wagtail_trash-3.0.0-py3-none-any.whl (22.1 kB view details)

Uploaded Python 3

File details

Details for the file wagtail-trash-3.0.0.tar.gz.

File metadata

  • Download URL: wagtail-trash-3.0.0.tar.gz
  • Upload date:
  • Size: 18.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.18

File hashes

Hashes for wagtail-trash-3.0.0.tar.gz
Algorithm Hash digest
SHA256 913a61d2020208180d8bbb85b112fd29bd61c3cad98072cafdd77ee39e852a98
MD5 9ae2f5757bc31cac6532be16f43dd5c6
BLAKE2b-256 29c3d034c504ad4401bc41736677a0a471c655b67fd928de491a3c5680a4ebe4

See more details on using hashes here.

File details

Details for the file wagtail_trash-3.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for wagtail_trash-3.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 edcbbb1395437247155559391f437239716aa6c4ad62340bc23e4ec615bee2ae
MD5 77d2b88059b6dd38cf7f5ec7c79655ce
BLAKE2b-256 6b255c72c44c473786b30c91eee343bdf7a984947da7bf89eb8a6c123d5bc7d1

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page