From 37c58fd9caefe67d0c650ea1e900ad83e78e8c1a Mon Sep 17 00:00:00 2001 From: Adam Tauber Date: Wed, 11 Mar 2015 18:57:36 +0100 Subject: [PATCH] [enh] plugin preferences - server-side ++ oscar theme --- searx/templates/oscar/preferences.html | 31 +++++++++++++++++++++----- searx/webapp.py | 29 +++++++++++++++++++++--- 2 files changed, 51 insertions(+), 9 deletions(-) diff --git a/searx/templates/oscar/preferences.html b/searx/templates/oscar/preferences.html index 126bdbd7b..65b7f4b4c 100644 --- a/searx/templates/oscar/preferences.html +++ b/searx/templates/oscar/preferences.html @@ -1,4 +1,4 @@ -{% from 'oscar/macros.html' import preferences_item_header, preferences_item_header_rtl, preferences_item_footer, preferences_item_footer_rtl %} +{% from 'oscar/macros.html' import preferences_item_header, preferences_item_header_rtl, preferences_item_footer, preferences_item_footer_rtl, checkbox_toggle %} {% extends "oscar/base.html" %} {% block title %}{{ _('preferences') }} - {% endblock %} {% block site_alert_warning_nojs %} @@ -16,6 +16,7 @@ @@ -139,11 +140,7 @@
{{ search_engine.name }} ({{ shortcuts[search_engine.name] }})
{% endif %}
-
- - - -
+ {{ checkbox_toggle('engine_' + search_engine.name|replace(' ', '_') + '__' + categ|replace(' ', '_'), (search_engine.name, categ) in blocked_engines) }}
{% if rtl %}
{{ search_engine.name }} ({{ shortcuts[search_engine.name] }})‎
@@ -157,6 +154,28 @@ {% endfor %} +
+ +
+
+ {% for plugin in plugins %} +
+
+

{{ plugin.name }}

+
+
+
{{ plugin.description }}
+
+ {{ checkbox_toggle('plugin_' + plugin.id, plugin.id not in allowed_plugins) }} +
+
+
+ {% endfor %} +
+
+

{{ _('These settings are stored in your cookies, this allows us not to store this data about you.') }}
diff --git a/searx/webapp.py b/searx/webapp.py index d2985c281..e3c372e03 100644 --- a/searx/webapp.py +++ b/searx/webapp.py @@ -317,8 +317,8 @@ def pre_request(): 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): + if ((plugin.default_on and plugin.id not in disabled_plugins) + or plugin.id in allowed_plugins): request.user_plugins.append(plugin) @@ -508,6 +508,7 @@ def preferences(): blocked_engines = get_blocked_engines(engines, request.cookies) else: # on save selected_categories = [] + post_disabled_plugins = [] locale = None autocomplete = '' method = 'POST' @@ -534,14 +535,34 @@ def preferences(): safesearch = pd elif pd_name.startswith('engine_'): if pd_name.find('__') > -1: - engine_name, category = pd_name.replace('engine_', '', 1).split('__', 1) + # TODO fix underscore vs space + engine_name, category = [x.replace('_', ' ') for x in + pd_name.replace('engine_', '', 1).split('__', 1)] if engine_name in engines and category in engines[engine_name].categories: blocked_engines.append((engine_name, category)) elif pd_name == 'theme': theme = pd if pd in themes else default_theme + elif pd_name.startswith('plugin_'): + plugin_id = pd_name.replace('plugin_', '', 1) + if not any(plugin.id == plugin_id for plugin in plugins): + continue + post_disabled_plugins.append(plugin_id) else: resp.set_cookie(pd_name, pd, max_age=cookie_max_age) + disabled_plugins = [] + allowed_plugins = [] + for plugin in plugins: + if plugin.default_on: + if plugin.id in post_disabled_plugins: + disabled_plugins.append(plugin.id) + elif plugin.id not in post_disabled_plugins: + allowed_plugins.append(plugin.id) + + resp.set_cookie('disabled_plugins', ','.join(disabled_plugins), max_age=cookie_max_age) + + resp.set_cookie('allowed_plugins', ','.join(allowed_plugins), max_age=cookie_max_age) + resp.set_cookie( 'blocked_engines', ','.join('__'.join(e) for e in blocked_engines), max_age=cookie_max_age @@ -591,6 +612,8 @@ def preferences(): autocomplete_backends=autocomplete_backends, shortcuts={y: x for x, y in engine_shortcuts.items()}, themes=themes, + plugins=plugins, + allowed_plugins=[plugin.id for plugin in request.user_plugins], theme=get_current_theme_name())