Skip to main content

Feature flags for Wagtail sites

Project description

Wagtail-Flags

Build Status Ethical open source

Feature flags allow you to toggle functionality based on configurable conditions.

Wagtail-Flags adds a Wagtail admin UI and Wagtail Site-based condition on top of Django-Flags. For a more complete overview of feature flags and how to use them, please see the Django-Flags documentation.

Feature flags in the Wagtail admin

Dependencies

  • Python 3.8+
  • Django 3.2 (LTS)+
  • Django-Flags 4.2
  • Wagtail 4.0+

It should be compatible at all intermediate versions, as well. If you find that it is not, please file an issue.

Installation

  1. Install Django-Flags and Wagtail-Flags:
pip install django-flags
pip install wagtail-flags
  1. Add flags and wagtailflags as installed apps in your Django settings.py:
INSTALLED_APPS = (
    ...
    'flags',
    'wagtailflags',
    ...
)

Usage

Please see the Django-Flags documentation for the most current information about defining and checking feature flags.

First, define the flag in Django settings.py:

FLAGS = {
    'MY_FLAG': []
}

Then use the flag in a Django template (mytemplate.html):

{% load feature_flags %}
{% flag_enabled 'MY_FLAG' as my_flag %}

{% if my_flag %}
  <div class="flagged-banner">
    I’m the result of a feature flag.
  </div>
{% endif %}

Next, configure a URL for that template (urls.py):

from django.urls import path
from django.views.generic import TemplateView

urlpatterns = [
    path(r'mypage/', TemplateView.as_view(template_name='mytemplate.html')),
]

Finally, add conditions for the flag in the Wagtail admin under "Settings", "Flags", "MY_FLAG":

Creating conditions in the Wagtail admin

Extended conditions

Wagtail-Flags adds the following conditions to Django-Flags:

site

Allows a flag to be enabled for a Wagtail site that matches the hostname and port in the condition value.

FLAGS = {
    'MY_FLAG': [
        {'condition': 'site', 'value': 'staging.mysite.com'}
    ],
}

Signals

Wagtail-Flags includes flag_enabled and flag_disabled signals that can be received when the "Enable for all requests" and "Disable for all requests" buttons are pressed in the admin. This is intended to enable things like front-end cache invalidation.

from django.dispatch import receiver

from wagtail.contrib.frontend_cache.utils import purge_url_from_cache

from wagtailflags.signals import flag_disabled, flag_enabled


@receiver(flag_enabled)
def purge_on_flag_enabled(sender, **kwargs):
    flag_name = kwargs["flag_name"]
    purge_url_from_cache(...)

@receiver(flag_disabled)
def purge_on_flag_disabled(sender, **kwargs):
    flag_name = kwargs["flag_name"]
    purge_url_from_cache(...)

Please note: These signals are only sent for manual presses of the "Enable for all requests" and "Disable for all requests" buttons in the admin. Other flag conditions may vary within and only be valid for a specific request cycle.

Getting help

Please add issues to the issue tracker.

Getting involved

General instructions on how to contribute can be found in CONTRIBUTING.

Licensing

  1. TERMS
  2. LICENSE
  3. CFPB Source Code Policy

Credits and references

  1. Forked from cfgov-refresh

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-flags-5.3.0.tar.gz (16.1 kB view details)

Uploaded Source

Built Distribution

wagtail_flags-5.3.0-py3-none-any.whl (23.4 kB view details)

Uploaded Python 3

File details

Details for the file wagtail-flags-5.3.0.tar.gz.

File metadata

  • Download URL: wagtail-flags-5.3.0.tar.gz
  • Upload date:
  • Size: 16.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.2

File hashes

Hashes for wagtail-flags-5.3.0.tar.gz
Algorithm Hash digest
SHA256 fb7c2e82fed1190b51a386abdc30e0f4f7e413f3c535dfc0dad65ae4c3ef36f7
MD5 cf6f106906bd849ae1bc7b1c94ed2710
BLAKE2b-256 210b44531eb2c1ac003cd9cab5991c7482338f006a5149c48dc2d1b5d39743d9

See more details on using hashes here.

Provenance

File details

Details for the file wagtail_flags-5.3.0-py3-none-any.whl.

File metadata

File hashes

Hashes for wagtail_flags-5.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d7aa66c6c80701350e53e575ccf5b46a80c3c6ff9e9be6733f3b17a753b9934b
MD5 6cf39f0cdd96fd9227760401ca5af9b8
BLAKE2b-256 80e3c5b7bac532f174508548c9c401e23939e3e223b8c7f82b83c19fd3192d30

See more details on using hashes here.

Provenance

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