Skip to main content

No project description provided

Project description

wagtailpurge

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

  • Django >= 3.1
  • Wagtail >= 2.12

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 upstream 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 / upstream cache service).

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 upstream 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 upstream 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 :)

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

wagtailpurge-0.3.0.tar.gz (18.0 kB view details)

Uploaded Source

Built Distribution

wagtailpurge-0.3.0-py2.py3-none-any.whl (21.0 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file wagtailpurge-0.3.0.tar.gz.

File metadata

  • Download URL: wagtailpurge-0.3.0.tar.gz
  • Upload date:
  • Size: 18.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.8

File hashes

Hashes for wagtailpurge-0.3.0.tar.gz
Algorithm Hash digest
SHA256 b2411c4e2346e5693713ce21be07c18b74ff993ec360adf433b9a5a39711a723
MD5 d0b821a8a02e8818210c344186b6a51e
BLAKE2b-256 4c6401bd9ec18754e4c56462b9aa9230acf5123550614129989b79ab01997eca

See more details on using hashes here.

File details

Details for the file wagtailpurge-0.3.0-py2.py3-none-any.whl.

File metadata

  • Download URL: wagtailpurge-0.3.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 21.0 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.8

File hashes

Hashes for wagtailpurge-0.3.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 9a27885b71e05578c87c5014b20be629e2e1bb0d9f29e862dc7e2178988f01c7
MD5 8936f5d7b017cfa44c1e8c9240d787ea
BLAKE2b-256 c0c328465b8778c11abd2a8c6f8909495748372623df42d0e879107e1d42f94d

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