mirror of
https://github.com/searxng/searxng.git
synced 2024-11-17 18:00:12 +01:00
[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,
|
self.engines.extend({'category': prefix,
|
||||||
'name': engine.name}
|
'name': engine.name}
|
||||||
for engine in categories[prefix]
|
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] == '!':
|
if query_part[0] == '!':
|
||||||
self.specific = True
|
self.specific = True
|
||||||
|
@ -411,9 +411,9 @@ class Search(object):
|
|||||||
# declared under the specific categories
|
# declared under the specific categories
|
||||||
for categ in self.categories:
|
for categ in self.categories:
|
||||||
self.engines.extend({'category': categ,
|
self.engines.extend({'category': categ,
|
||||||
'name': x.name}
|
'name': engine.name}
|
||||||
for x in categories[categ]
|
for engine in categories[categ]
|
||||||
if x.name not in self.blocked_engines)
|
if (engine.name, categ) not in self.blocked_engines)
|
||||||
|
|
||||||
# do search-request
|
# do search-request
|
||||||
def search(self, request):
|
def search(self, request):
|
||||||
|
@ -99,7 +99,7 @@
|
|||||||
<td>{{ search_engine.name }} ({{ shortcuts[search_engine.name] }})</td>
|
<td>{{ search_engine.name }} ({{ shortcuts[search_engine.name] }})</td>
|
||||||
<td>{{ _(categ) }}</td>
|
<td>{{ _(categ) }}</td>
|
||||||
<td class="engine_checkbox">
|
<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="allow" for="engine_{{ categ|replace(' ', '_') }}_{{ search_engine.name|replace(' ', '_') }}">{{ _('Allow') }}</label>
|
||||||
<label class="deny" for="engine_{{ categ|replace(' ', '_') }}_{{ search_engine.name|replace(' ', '_') }}">{{ _('Block') }}</label>
|
<label class="deny" for="engine_{{ categ|replace(' ', '_') }}_{{ search_engine.name|replace(' ', '_') }}">{{ _('Block') }}</label>
|
||||||
</td>
|
</td>
|
||||||
|
@ -87,7 +87,7 @@
|
|||||||
<td>{{ search_engine.name }} ({{ shortcuts[search_engine.name] }})</td>
|
<td>{{ search_engine.name }} ({{ shortcuts[search_engine.name] }})</td>
|
||||||
<td>{{ _(categ) }}</td>
|
<td>{{ _(categ) }}</td>
|
||||||
<td class="engine_checkbox">
|
<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="allow" for="engine_{{ categ|replace(' ', '_') }}_{{ search_engine.name|replace(' ', '_') }}">{{ _('Allow') }}</label>
|
||||||
<label class="deny" for="engine_{{ categ|replace(' ', '_') }}_{{ search_engine.name|replace(' ', '_') }}">{{ _('Block') }}</label>
|
<label class="deny" for="engine_{{ categ|replace(' ', '_') }}_{{ search_engine.name|replace(' ', '_') }}">{{ _('Block') }}</label>
|
||||||
</td>
|
</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">{{ search_engine.name }} ({{ shortcuts[search_engine.name] }})</div>
|
||||||
<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">
|
<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-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>
|
<label class="btn btn-danger label_hide_if_not_checked" for="engine_{{ categ|replace(' ', '_') }}_{{ search_engine.name|replace(' ', '_') }}">{{ _('Allow') }}</label>
|
||||||
</div>
|
</div>
|
||||||
|
@ -231,7 +231,21 @@ def prettify_url(url):
|
|||||||
|
|
||||||
def get_blocked_engines(engines, cookies):
|
def get_blocked_engines(engines, cookies):
|
||||||
if 'blocked_engines' not in 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(',')
|
blocked_engine_strings = cookies.get('blocked_engines', '').split(',')
|
||||||
if engine in engines]
|
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
|
import hashlib
|
||||||
|
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
from itertools import chain
|
|
||||||
from urllib import urlencode
|
from urllib import urlencode
|
||||||
from flask import (
|
from flask import (
|
||||||
Flask, request, render_template, url_for, Response, make_response,
|
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:
|
if autocomplete not in autocomplete_backends:
|
||||||
autocomplete = None
|
autocomplete = None
|
||||||
|
|
||||||
nonblocked_categories = (engines[e].categories
|
nonblocked_categories = set(category for engine_name in engines
|
||||||
for e in engines
|
for category in engines[engine_name].categories
|
||||||
if e not in blocked_engines)
|
if (engine_name, category) not in blocked_engines)
|
||||||
|
|
||||||
nonblocked_categories = set(chain.from_iterable(nonblocked_categories))
|
|
||||||
|
|
||||||
if 'categories' not in kwargs:
|
if 'categories' not in kwargs:
|
||||||
kwargs['categories'] = ['general']
|
kwargs['categories'] = ['general']
|
||||||
@ -492,19 +489,17 @@ def preferences():
|
|||||||
elif pd_name == 'method':
|
elif pd_name == 'method':
|
||||||
method = pd
|
method = pd
|
||||||
elif pd_name.startswith('engine_'):
|
elif pd_name.startswith('engine_'):
|
||||||
engine_name = pd_name.replace('engine_', '', 1)
|
if pd_name.find('__') > -1:
|
||||||
if engine_name in engines:
|
engine_name, category = pd_name.replace('engine_', '', 1).split('__', 1)
|
||||||
blocked_engines.append(engine_name)
|
if engine_name in engines and category in engines[engine_name].categories:
|
||||||
|
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
|
||||||
else:
|
else:
|
||||||
resp.set_cookie(pd_name, pd, max_age=cookie_max_age)
|
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(
|
resp.set_cookie(
|
||||||
'blocked_engines', ','.join(blocked_engines),
|
'blocked_engines', ','.join('__'.join(e) for e in blocked_engines),
|
||||||
max_age=cookie_max_age
|
max_age=cookie_max_age
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user