[enh] per user plugin switch

This commit is contained in:
Adam Tauber 2015-03-10 20:44:02 +01:00
parent 00cc4dcbf4
commit cae22bfc76
2 changed files with 14 additions and 2 deletions

View File

@ -20,7 +20,7 @@ class PluginStore():
self.plugins = [] self.plugins = []
def __iter__(self): def __iter__(self):
for plugin in plugins: for plugin in self.plugins:
yield plugin yield plugin
def register(self, *plugins): def register(self, *plugins):
@ -33,7 +33,7 @@ class PluginStore():
def call(self, plugin_type, request, *args, **kwargs): def call(self, plugin_type, request, *args, **kwargs):
ret = True ret = True
for plugin in self.plugins: for plugin in request.user_plugins:
if hasattr(plugin, plugin_type): if hasattr(plugin, plugin_type):
ret = getattr(plugin, plugin_type)(request, *args, **kwargs) ret = getattr(plugin, plugin_type)(request, *args, **kwargs)
if not ret: if not ret:

View File

@ -305,6 +305,18 @@ def render(template_name, override_theme=None, **kwargs):
'{}/{}'.format(kwargs['theme'], template_name), **kwargs) '{}/{}'.format(kwargs['theme'], template_name), **kwargs)
@app.before_request
def pre_request():
request.user_plugins = []
allowed_plugins = request.cookies.get('allowed_plugins', '').split(',')
disabled_plugins = request.cookies.get('disabled_plugins', '').split(',')
for plugin in plugins:
if ((plugin.default_on and plugin.name not in disabled_plugins)
or plugin.name in allowed_plugins):
request.user_plugins.append(plugin)
@app.route('/search', methods=['GET', 'POST']) @app.route('/search', methods=['GET', 'POST'])
@app.route('/', methods=['GET', 'POST']) @app.route('/', methods=['GET', 'POST'])
def index(): def index():