commit: cae22bfc7609d00f987e679cf6d048873d268d84
parent 00cc4dcbf44d9ecea89befb08cae4ee5561c4247
Author: Adam Tauber <asciimoo@gmail.com>
Date: Tue, 10 Mar 2015 20:44:02 +0100
[enh] per user plugin switch
Diffstat:
2 files changed, 14 insertions(+), 2 deletions(-)
diff --git a/searx/plugins/__init__.py b/searx/plugins/__init__.py
@@ -20,7 +20,7 @@ class PluginStore():
self.plugins = []
def __iter__(self):
- for plugin in plugins:
+ for plugin in self.plugins:
yield plugin
def register(self, *plugins):
@@ -33,7 +33,7 @@ class PluginStore():
def call(self, plugin_type, request, *args, **kwargs):
ret = True
- for plugin in self.plugins:
+ for plugin in request.user_plugins:
if hasattr(plugin, plugin_type):
ret = getattr(plugin, plugin_type)(request, *args, **kwargs)
if not ret:
diff --git a/searx/webapp.py b/searx/webapp.py
@@ -305,6 +305,18 @@ def render(template_name, override_theme=None, **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('/', methods=['GET', 'POST'])
def index():