mirror of
https://github.com/searxng/searxng
synced 2024-01-01 18:24:07 +00:00
[enh] plugin preferences - server-side ++ oscar theme
This commit is contained in:
parent
9eeb36c787
commit
37c58fd9ca
@ -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" %}
|
{% extends "oscar/base.html" %}
|
||||||
{% block title %}{{ _('preferences') }} - {% endblock %}
|
{% block title %}{{ _('preferences') }} - {% endblock %}
|
||||||
{% block site_alert_warning_nojs %}
|
{% block site_alert_warning_nojs %}
|
||||||
@ -16,6 +16,7 @@
|
|||||||
<ul class="nav nav-tabs nav-justified hide_if_nojs" role="tablist" style="margin-bottom:20px;">
|
<ul class="nav nav-tabs nav-justified hide_if_nojs" role="tablist" style="margin-bottom:20px;">
|
||||||
<li class="active"><a href="#tab_general" role="tab" data-toggle="tab">{{ _('General') }}</a></li>
|
<li class="active"><a href="#tab_general" role="tab" data-toggle="tab">{{ _('General') }}</a></li>
|
||||||
<li><a href="#tab_engine" role="tab" data-toggle="tab">{{ _('Engines') }}</a></li>
|
<li><a href="#tab_engine" role="tab" data-toggle="tab">{{ _('Engines') }}</a></li>
|
||||||
|
<li><a href="#tab_plugins" role="tab" data-toggle="tab">{{ _('Plugins') }}</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
<!-- Tab panes -->
|
<!-- Tab panes -->
|
||||||
@ -139,11 +140,7 @@
|
|||||||
<div class="col-xs-6 col-sm-4 col-md-4">{{ search_engine.name }} ({{ shortcuts[search_engine.name] }})</div>
|
<div class="col-xs-6 col-sm-4 col-md-4">{{ search_engine.name }} ({{ shortcuts[search_engine.name] }})</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<div class="col-xs-6 col-sm-4 col-md-4">
|
<div class="col-xs-6 col-sm-4 col-md-4">
|
||||||
<div class="checkbox">
|
{{ checkbox_toggle('engine_' + search_engine.name|replace(' ', '_') + '__' + categ|replace(' ', '_'), (search_engine.name, categ) in blocked_engines) }}
|
||||||
<input class="hidden" type="checkbox" id="engine_{{ categ|replace(' ', '_') }}_{{ search_engine.name|replace(' ', '_') }}" name="engine_{{ search_engine.name }}__{{ categ }}"{% if (search_engine.name, categ) in blocked_engines %} checked="checked"{% endif %} />
|
|
||||||
<label class="btn btn-success label_hide_if_checked" for="engine_{{ categ|replace(' ', '_') }}_{{ search_engine.name|replace(' ', '_') }}">{{ _('Block') }}</label>
|
|
||||||
<label class="btn btn-danger label_hide_if_not_checked" for="engine_{{ categ|replace(' ', '_') }}_{{ search_engine.name|replace(' ', '_') }}">{{ _('Allow') }}</label>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
{% if rtl %}
|
{% if rtl %}
|
||||||
<div class="col-xs-6 col-sm-4 col-md-4">{{ search_engine.name }} ({{ shortcuts[search_engine.name] }})‎</div>
|
<div class="col-xs-6 col-sm-4 col-md-4">{{ search_engine.name }} ({{ shortcuts[search_engine.name] }})‎</div>
|
||||||
@ -157,6 +154,28 @@
|
|||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="tab-pane active_if_nojs" id="tab_plugins">
|
||||||
|
<noscript>
|
||||||
|
<h3>{{ _('Plugins') }}</h3>
|
||||||
|
</noscript>
|
||||||
|
<fieldset>
|
||||||
|
<div class="container-fluid">
|
||||||
|
{% for plugin in plugins %}
|
||||||
|
<div class="panel panel-default">
|
||||||
|
<div class="panel-heading">
|
||||||
|
<h3 class="panel-title">{{ plugin.name }}</h3>
|
||||||
|
</div>
|
||||||
|
<div class="panel-body">
|
||||||
|
<div class="col-xs-6 col-sm-4 col-md-6">{{ plugin.description }}</div>
|
||||||
|
<div class="col-xs-6 col-sm-4 col-md-6">
|
||||||
|
{{ checkbox_toggle('plugin_' + plugin.id, plugin.id not in allowed_plugins) }}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endfor %}
|
||||||
|
</div>
|
||||||
|
</fieldset>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<p class="text-muted" style="margin:20px 0;">{{ _('These settings are stored in your cookies, this allows us not to store this data about you.') }}
|
<p class="text-muted" style="margin:20px 0;">{{ _('These settings are stored in your cookies, this allows us not to store this data about you.') }}
|
||||||
<br />
|
<br />
|
||||||
|
@ -317,8 +317,8 @@ def pre_request():
|
|||||||
allowed_plugins = request.cookies.get('allowed_plugins', '').split(',')
|
allowed_plugins = request.cookies.get('allowed_plugins', '').split(',')
|
||||||
disabled_plugins = request.cookies.get('disabled_plugins', '').split(',')
|
disabled_plugins = request.cookies.get('disabled_plugins', '').split(',')
|
||||||
for plugin in plugins:
|
for plugin in plugins:
|
||||||
if ((plugin.default_on and plugin.name not in disabled_plugins)
|
if ((plugin.default_on and plugin.id not in disabled_plugins)
|
||||||
or plugin.name in allowed_plugins):
|
or plugin.id in allowed_plugins):
|
||||||
request.user_plugins.append(plugin)
|
request.user_plugins.append(plugin)
|
||||||
|
|
||||||
|
|
||||||
@ -508,6 +508,7 @@ def preferences():
|
|||||||
blocked_engines = get_blocked_engines(engines, request.cookies)
|
blocked_engines = get_blocked_engines(engines, request.cookies)
|
||||||
else: # on save
|
else: # on save
|
||||||
selected_categories = []
|
selected_categories = []
|
||||||
|
post_disabled_plugins = []
|
||||||
locale = None
|
locale = None
|
||||||
autocomplete = ''
|
autocomplete = ''
|
||||||
method = 'POST'
|
method = 'POST'
|
||||||
@ -534,14 +535,34 @@ def preferences():
|
|||||||
safesearch = pd
|
safesearch = pd
|
||||||
elif pd_name.startswith('engine_'):
|
elif pd_name.startswith('engine_'):
|
||||||
if pd_name.find('__') > -1:
|
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:
|
if engine_name in engines and category in engines[engine_name].categories:
|
||||||
blocked_engines.append((engine_name, category))
|
blocked_engines.append((engine_name, category))
|
||||||
elif pd_name == 'theme':
|
elif pd_name == 'theme':
|
||||||
theme = pd if pd in themes else default_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:
|
else:
|
||||||
resp.set_cookie(pd_name, pd, max_age=cookie_max_age)
|
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(
|
resp.set_cookie(
|
||||||
'blocked_engines', ','.join('__'.join(e) for e in blocked_engines),
|
'blocked_engines', ','.join('__'.join(e) for e in blocked_engines),
|
||||||
max_age=cookie_max_age
|
max_age=cookie_max_age
|
||||||
@ -591,6 +612,8 @@ def preferences():
|
|||||||
autocomplete_backends=autocomplete_backends,
|
autocomplete_backends=autocomplete_backends,
|
||||||
shortcuts={y: x for x, y in engine_shortcuts.items()},
|
shortcuts={y: x for x, y in engine_shortcuts.items()},
|
||||||
themes=themes,
|
themes=themes,
|
||||||
|
plugins=plugins,
|
||||||
|
allowed_plugins=[plugin.id for plugin in request.user_plugins],
|
||||||
theme=get_current_theme_name())
|
theme=get_current_theme_name())
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user