django-waffle

Learn how to use this popular feature flipper for helping you to develop and test new features live instead of only in development.

resources

demoforms/settings.py

INSTALLED_APPS = (
    ...
    'waffle',
)
main/views.py
from django.views.generic import FormView
from django.shortcuts import render_to_response
from django.template import RequestContext

from waffle.decorators import waffle_flag, flag_is_active

from main.forms import CreditCardForm

class MainView(FormView):
    template_name = 'main/index.html'
    form_class = CreditCardForm

    def get_context_data(self, kwargs):
        context = super(MainView, self).get_context_data(kwargs)

        if flag_is_active(self.request, 'information'):
            context['data'] = 'Flag is active'
        else:
            context['data'] = 'Flag is inactive'

        return context

@waffle_flag('information')
def info(request):
    template_name = 'main/information.html'

    return render_to_response(template_name,
        {},
        context_instance=RequestContext(request))
comments powered by Disqus