django-waffle

A feature flipper for Django
Download

django-waffle Ranking & Summary

Advertisement

  • Rating:
  • License:
  • BSD License
  • Publisher Name:
  • James Socol

django-waffle Tags


django-waffle Description

A feature flipper for Django django-waffle is a feature flipper for Django. You can define the conditions for which a flag should be active, and use it in a number of ways.Installation:To start using Waffle, you just need to add it to your INSTALLED_APPS and MIDDLEWARE_CLASSES:INSTALLED_APPS = ( # ... 'waffle', # ...)MIDDLEWARE_CLASSES = ( # ... 'waffle.middleware.WaffleMiddleware', # ...)Since Waffle will be setting cookies on response objects, you probably want it below any middleware that tweaks cookies before sending them out.Creating a FlagCreating and managing flags is done through the Django admin interface. Each feature flag is represented by a Flag object, which has several properties.Name: The name of the flag. Will be used to identify the flag everywhere.Everyone: You can flip this flag on (Yes) or off (No) for everyone, overriding all other settings. Leave as Unknown to use normally.Percent: A percentage of users for whom the flag will be active. This is maintained through cookies, so clever users can get around it. Still, it's the most common case.Superusers: Is this flag always active for superusers?Staff: Is this flag always active for staff?Authenticated: Is this flag always active for authenticated users?Groups: A list of group IDs for which this flag will always be active.Users: A list of user IDs for which this flag will always be active.You can combine multiple settings here. For example, you could offer a feature to 12% of users and all superusers. When combining settings, the flag will be active for the user if any of the settings matches for them.Using a FlagFlags can be used in templates, in views, or wrapped around entire views.If you try to use a flag that is not defined, it will always be inactive.Using a Flag in TemplatesJingo/Jinja2To use a flag in a Jinja2 template via Jingo, you can simply do:{% if waffle('flag_name') %} Content if flag is active{% endif %}You can also add an {% else %} section, of course:{% if waffle('flag_name') %} Flag is active!{% else %} Flag is inactive!{% endif %}Django TemplatesTo use a flag in vanilla Django templates, you can use the waffle tag:{% load waffle_tags %}{% waffle flag_name %} Content if flag is active{% endwaffle %}The {% waffle %} tag also supports an {% else %} section:{% waffle flag_name %} Flag is active!{% else %} Flag is inactive!{% endwaffle %}Using a Flag in ViewsTo use a flag in a view, you just need waffle.is_active:import waffledef my_view(request): if waffle.is_active(request, 'flag_name'): # Behavior if flag is active. else: # Behavior if flag is inactive.Wraping a Whole View in a FlagYou can also wrap an entire view in a flag:from waffle.decorators import waffle@waffle('flag_name')def my_view(request): # View only available if flag is active.If the flag is not active for the request, the view will be a 404.You can reverse this by putting an exclamation point at the start of the flag name, for example:@waffle('!flag_name')def my_view(request): # View is only available if flag is INactive. Requirements: · Python


django-waffle Related Software