Skip to content

Instantly share code, notes, and snippets.

@slacksec
Created February 16, 2016 11:36
Show Gist options
  • Save slacksec/97e25c95f8a8bcb454f9 to your computer and use it in GitHub Desktop.
Save slacksec/97e25c95f8a8bcb454f9 to your computer and use it in GitHub Desktop.
from flask import current_app
class FeatureFlags(object):
def __init__(self, app=None):
if app is not None:
self.init_app(app)
def init_app(self, app):
app.config.setdefault('FEATURE_FLAGS’, {})
if hasattr(app, "add_template_test"):
app.add_template_test(self.in_config, name='active_feature')
else:
app.jinja_env.tests['active_feature'] = self.in_config
app.extensions['FeatureFlags'] = self
def in_config(self, feature):
try:
return current_app.config['FEATURE_FLAGS'][feature]
except (AttributeError, KeyError):
return False
def is_active(feature):
feature_flagger = current_app.extensions['FeatureFlags']
return feature_flagger.in_config(feature)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment