-
-
Save philippeowagner/765a585fb2ce14bf9c99 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
from waffle import TEST_COOKIE_NAME, flag_is_active | |
from waffle.middleware import WaffleMiddleware | |
# FIXME: only works if TEST_COOKIE_NAME ends with the flag name | |
TEST_COOKIE_PREFIX = TEST_COOKIE_NAME.split('%s')[0] | |
class AlwaysWaffleMiddleware(WaffleMiddleware): | |
""" | |
version of the waffle middle ware that will set the cookie any time the waffle | |
get parameters are in the url. not just on views where the feature flag actually | |
happens do be checked. | |
""" | |
def process_response(self, request, response): | |
# sets cookies for any flags in the get parameters | |
for key, value in request.GET.items(): | |
if key.startswith(TEST_COOKIE_PREFIX): | |
flag_name = key.replace(TEST_COOKIE_PREFIX, '', 1) | |
# implicitly sets the cookie and adds it to request | |
flag_is_active(request, flag_name) | |
return super(BetterWaffleMiddleware, self).process_response(request, response) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment