Skip to main content

A simple, customisable, feature flipper

Project description

A set of simple feature flipper template tags that can be easily extended.

Installation

To install this, simply pip install django-feature-flipper.

Usage

Configure your INSTALLED_APPS in settings.py

INSTALLED_APPS = (
  ...
  'feature_flipper',
  ...
)

This gives you access to the basic feature flipping models and template tags. You can then use the basic FeatureFlipper that turns flags on and off depending on your user, or customise your own.

Basic Feature Flipper

Set the flag choices in your settings.py file as:

FEATURE_FLIPPER_FLAGS = (
  ('simple_feature', u'Simple Feature'),
  ('beta_testing', u'Beta Testing'),
)

When you add features, simply add flags here and your application will be able to access the new flags immediately.

Custom Feature Flipper

To customise the feature flipper you can just extend feature_flipper.models.AbstractFeatureFlipper with your own field. This provides a major advantage over the basic flipper by letting you determine your own reference for filtering out whether users get a feature or not.

First, extend the AbstractFeatureFlipper model:

from feature_flipper.models import AbstractFeatureFlipper


class MyFeatureFlipper(AbstractFeatureFlipper):
  """
  """
  USER_FEATURE_FIELD = 'company'

  company = models.ForeignKey('myapp.Company')

The USER_FEATURE_FIELD sets the field that should be used for lookups when determining whether to show the feature to a user. The final part is to reference this in your settings.py:

FEATURE_FLIPPER_MODEL = 'myapp.MyFeatureFlipper',

Using in Templates

To use the feature flipper in your templates, just load the feature_flipper library and use the flipper template tag:

{% load feature_flipper %}

<ul class="features">
  {% flipper request.user "simple_feature" %}
  <li><a href="/simple">Simple feature</a></li>
  {% endflipper %}

  {% flipper request.user "beta_testing" %}
  <li><a href="/testing">Beta-testing feature</a></li>
  {% endflipper %}
</ul>

The feature tag

The feature template tag is a simple template tag that takes two arguments:

  1. The user requesting access
  2. The feature string to check for

For custom feature flippers, the user argument is simply the alternative user identifier, for example the user’s organisation.

Supported Django Versions

This supports Django 1.9 and later.

Feature Flipper Django
0.0.7 1.9

Project details


Download files

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

Files for django-feature-flipper, version 0.0.8
Filename, size File type Python version Upload date Hashes
Filename, size django_feature_flipper-0.0.8-py2.7.egg (13.9 kB) File type Egg Python version 2.7 Upload date Hashes View
Filename, size django_feature_flipper-0.0.8-py2-none-any.whl (9.7 kB) File type Wheel Python version 2.7 Upload date Hashes View
Filename, size django-feature-flipper-0.0.8.tar.gz (5.0 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page