mirror of https://github.com/searxng/searxng.git
[enh] category specific engine deactivation - closes #205
This commit is contained in:
parent
268e0516ee
commit
1de781a143
|
@ -107,7 +107,7 @@ class Query(object):
|
|||
self.engines.extend({'category': prefix,
|
||||
'name': engine.name}
|
||||
for engine in categories[prefix]
|
||||
if engine not in self.blocked_engines)
|
||||
if (engine.name, prefix) not in self.blocked_engines)
|
||||
|
||||
if query_part[0] == '!':
|
||||
self.specific = True
|
||||
|
|
|
@ -411,9 +411,9 @@ class Search(object):
|
|||
# declared under the specific categories
|
||||
for categ in self.categories:
|
||||
self.engines.extend({'category': categ,
|
||||
'name': x.name}
|
||||
for x in categories[categ]
|
||||
if x.name not in self.blocked_engines)
|
||||
'name': engine.name}
|
||||
for engine in categories[categ]
|
||||
if (engine.name, categ) not in self.blocked_engines)
|
||||
|
||||
# do search-request
|
||||
def search(self, request):
|
||||
|
|
|
@ -99,7 +99,7 @@
|
|||
<td>{{ search_engine.name }} ({{ shortcuts[search_engine.name] }})</td>
|
||||
<td>{{ _(categ) }}</td>
|
||||
<td class="engine_checkbox">
|
||||
<input type="checkbox" id="engine_{{ categ|replace(' ', '_') }}_{{ search_engine.name|replace(' ', '_') }}" name="engine_{{ search_engine.name }}"{% if search_engine.name in blocked_engines %} checked="checked"{% endif %} />
|
||||
<input 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="allow" for="engine_{{ categ|replace(' ', '_') }}_{{ search_engine.name|replace(' ', '_') }}">{{ _('Allow') }}</label>
|
||||
<label class="deny" for="engine_{{ categ|replace(' ', '_') }}_{{ search_engine.name|replace(' ', '_') }}">{{ _('Block') }}</label>
|
||||
</td>
|
||||
|
|
|
@ -87,7 +87,7 @@
|
|||
<td>{{ search_engine.name }} ({{ shortcuts[search_engine.name] }})</td>
|
||||
<td>{{ _(categ) }}</td>
|
||||
<td class="engine_checkbox">
|
||||
<input type="checkbox" id="engine_{{ categ|replace(' ', '_') }}_{{ search_engine.name|replace(' ', '_') }}" name="engine_{{ search_engine.name }}"{% if search_engine.name in blocked_engines %} checked="checked"{% endif %} />
|
||||
<input 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="allow" for="engine_{{ categ|replace(' ', '_') }}_{{ search_engine.name|replace(' ', '_') }}">{{ _('Allow') }}</label>
|
||||
<label class="deny" for="engine_{{ categ|replace(' ', '_') }}_{{ search_engine.name|replace(' ', '_') }}">{{ _('Block') }}</label>
|
||||
</td>
|
||||
|
|
|
@ -128,7 +128,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">
|
||||
<div class="checkbox">
|
||||
<input class="hidden" type="checkbox" id="engine_{{ categ|replace(' ', '_') }}_{{ search_engine.name|replace(' ', '_') }}" name="engine_{{ search_engine.name }}"{% if search_engine.name in blocked_engines %} checked="checked"{% endif %} />
|
||||
<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>
|
||||
|
|
|
@ -231,7 +231,21 @@ def prettify_url(url):
|
|||
|
||||
def get_blocked_engines(engines, cookies):
|
||||
if 'blocked_engines' not in cookies:
|
||||
return [engine for engine in engines if engines[engine].disabled]
|
||||
return [(engine, category) for engine in engines for category in engines.category if engines[engine].disabled]
|
||||
|
||||
return [engine for engine in cookies.get('blocked_engines', '').split(',')
|
||||
if engine in engines]
|
||||
blocked_engine_strings = cookies.get('blocked_engines', '').split(',')
|
||||
blocked_engines = []
|
||||
|
||||
if not blocked_engine_strings:
|
||||
return blocked_engines
|
||||
|
||||
for engine_string in blocked_engine_strings:
|
||||
if engine_string.find('__') > -1:
|
||||
engine, category = engine_string.split('__', 1)
|
||||
if engine in engines and category in engines[engine].categories:
|
||||
blocked_engines.append((engine, category))
|
||||
elif engine_string in engines:
|
||||
for category in engines[engine_string].categories:
|
||||
blocked_engines.append((engine_string, category))
|
||||
|
||||
return blocked_engines
|
||||
|
|
|
@ -28,7 +28,6 @@ import os
|
|||
import hashlib
|
||||
|
||||
from datetime import datetime, timedelta
|
||||
from itertools import chain
|
||||
from urllib import urlencode
|
||||
from flask import (
|
||||
Flask, request, render_template, url_for, Response, make_response,
|
||||
|
@ -234,11 +233,9 @@ def render(template_name, override_theme=None, **kwargs):
|
|||
if autocomplete not in autocomplete_backends:
|
||||
autocomplete = None
|
||||
|
||||
nonblocked_categories = (engines[e].categories
|
||||
for e in engines
|
||||
if e not in blocked_engines)
|
||||
|
||||
nonblocked_categories = set(chain.from_iterable(nonblocked_categories))
|
||||
nonblocked_categories = set(category for engine_name in engines
|
||||
for category in engines[engine_name].categories
|
||||
if (engine_name, category) not in blocked_engines)
|
||||
|
||||
if 'categories' not in kwargs:
|
||||
kwargs['categories'] = ['general']
|
||||
|
@ -492,21 +489,19 @@ def preferences():
|
|||
elif pd_name == 'method':
|
||||
method = pd
|
||||
elif pd_name.startswith('engine_'):
|
||||
engine_name = pd_name.replace('engine_', '', 1)
|
||||
if engine_name in engines:
|
||||
blocked_engines.append(engine_name)
|
||||
if pd_name.find('__') > -1:
|
||||
engine_name, category = 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
|
||||
else:
|
||||
resp.set_cookie(pd_name, pd, max_age=cookie_max_age)
|
||||
|
||||
user_blocked_engines = request.cookies.get('blocked_engines', '').split(',') # noqa
|
||||
|
||||
if sorted(blocked_engines) != sorted(user_blocked_engines):
|
||||
resp.set_cookie(
|
||||
'blocked_engines', ','.join(blocked_engines),
|
||||
max_age=cookie_max_age
|
||||
)
|
||||
resp.set_cookie(
|
||||
'blocked_engines', ','.join('__'.join(e) for e in blocked_engines),
|
||||
max_age=cookie_max_age
|
||||
)
|
||||
|
||||
if locale:
|
||||
resp.set_cookie(
|
||||
|
|
Loading…
Reference in New Issue