Skip to main content
Archived

This project has been archived by its maintainers, and is no longer receiving any updates.

wagtailpurge

Trigger cache purges from within the Wagtail CMS. The app is tested for compatibility with:

  • Django >= 3.2
  • Wagtail >= 2.16

Get started

  1. Install this app with pip install wagtailpurge
  2. Add wagtailpurge to your INSTALLED_APPS
  3. From the shell, run python manage.py migrate wagtailpurge to create the necessary database tables
  4. Log into Wagtail and look out for the Purge menu item :)

By default, only superusers can submit purge requests, but permissions for individual request types can easily be applied to your existing groups to make the functionality available to others.

What can I purge?

1. Django caches

Utilizes Django's low-level cache API to clear a cache from your project's CACHES setting value.

NOTE: This option is only available when CACHES contains at least one item.

2. Individual URLs

Utilizes Wagtail's wagtail.contrib.frontend_cache app to purge a single URL of your choosing from a CDN or downstream cache. The URL can be anything from a page URL to a harcoded Django view URL, or even a URL completely out of the app's control (as long as it's on a domain managed by the same CDN / downstream cache account).

NOTE: This option is only available when wagtail.contrib.frontend_cache is installed.

3. Wagtail page URLs

Utilizes Wagtail's wagtail.contrib.frontend_cache app to purge selected page URLs from a CDN or downstream cache. You can easily purge sections of the tree by choosing to purge children or descendants of the selected page.

NOTE: This option is only available when wagtail.contrib.frontend_cache is installed.

4. Wagtail image renditions

Deletes all existing renditions for a Wagtail image (or images) of your choosing.

If the wagtail.contrib.frontend_cache app is installed, purge requests will also be sent to your CDN or downstream cache for the URL of each rendition, allowing the users to download freshly generated ones.

5. Custom purge requests

If you want to purge something else, it's possible to add your own model class with the fields and functionality you need. The only requirements are that you use BasePurgeRequest as a base, and that you add a process() method to handle the actual 'purging' of each request.

Here is an example:

# myproject/purge/models.py

from django.db import models
from django.forms.widgets import RadioSelect
from wagtailcache.models import BasePurgeRequest
from .utils import purge_chimp


class NaughtinessCategoryChoices(models.TextChoices):
    BITING = "biting", "Biting"
    SCRATCHING = "scratching", "Scratching"
    TOMFOOLERY = "tomfoolery", "General tomfoolery"


class NaughtyChimpPurgeRequest(BasePurgeRequest):
    # Add custom fields
    name = models.CharField(
        max_length=100,
        help_text="e.g. Peanuts",
    )
    category = models.CharField(
        max_length=30,
        choices=NaughtinessCategoryChoices.choices
    )

    # Add panels to show custom fields in the submit form
    panels = (
        FieldPanel("name"),
        FieldPanel("category", widget=RadioSelect())
    )

    # Optionally override the menu label and icon
    purge_menu_label = "Naughty chimp"
    purge_menu_icon = "warning"

    # Optionally add columns to the listing
    list_display_extra = ["name", "category", "custom_method"]

    # Optionally add filter options to the listing
    list_filter_extra = ["category"]

    def process(self) -> None:
        """
        Implements 'handling' for this purge request. The method doesn't need to
        return anything, and any exceptions raised here will be logged
        automatically.
        """
        purge_chimp(self.name, self.category)

    def custom_method(self) -> str:
        """
        Include non-field columns in the listing by adding a model
        method to return what you need, and including the method name
        in `list_display_extra`.
        """
        return "BANANA!"

Once you have defined your custom model:

  1. Ensure the app with the updated models.py (e.g. "myproject.purge") is included in your project's INSTALLED_APPS setting.
  2. From the shell, run python manage.py makemigrations appname to create database migrations for your app.
  3. From the shell, run python manage.py migrate to apply the migration to your database.
  4. Log into Wagtail and look out for your new option in the Purge menu :)

Metadata

Release files for wagtailpurge 1.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 wagtailpurge 1.0
File Size Uploaded Provenance Actions
wagtailpurge-1.0.tar.gz 18.3 kB Without provenance Details for wagtailpurge-1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for wagtailpurge 1.0
File Interpreter ABI Platform Actions
wagtailpurge-1.0-py2.py3-none-any.whl Python 2, Python 3 none any Details for wagtailpurge-1.0-py2.py3-none-any.whl

Total release size: 39.6 kB

Release files / wagtailpurge-1.0.tar.gz

Download URL wagtailpurge-1.0.tar.gz
Size 18.3 kB
Tags Source
SHA-256 checksum
How to use checksums
d4ca94d678c28118cc5405770399e2e727cced461dea5397d5664f488ec9f832
BLAKE2b-256 checksum
How to use checksums
b79707f7333f46b87ac832cc88724804a091b9b66e3a117db790624a49b940ce
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.14

Release files / wagtailpurge-1.0-py2.py3-none-any.whl

Download URL wagtailpurge-1.0-py2.py3-none-any.whl
Size 21.3 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
d2ab510d51e2d3dd1935a60255a387b699bc7551914917a5ffa54348ec0b6fcb
BLAKE2b-256 checksum
How to use checksums
1ba903030e19fb36f6bd52b87c10f4062ea234017ea02471e963e90a33f2c1e2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.14

Security for wagtailpurge 1.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