forked from zaclys/searxng
Merge pull request #536 from kvch/general-minor-refactors
General minor refactors
This commit is contained in:
commit
11c2262055
|
@ -20,10 +20,10 @@ language_codes = (
|
||||||
("ar_XA", "Arabic", "Arabia"),
|
("ar_XA", "Arabic", "Arabia"),
|
||||||
("bg_BG", "Bulgarian", "Bulgaria"),
|
("bg_BG", "Bulgarian", "Bulgaria"),
|
||||||
("cs_CZ", "Czech", "Czech Republic"),
|
("cs_CZ", "Czech", "Czech Republic"),
|
||||||
("de_DE", "German", "Germany"),
|
|
||||||
("da_DK", "Danish", "Denmark"),
|
("da_DK", "Danish", "Denmark"),
|
||||||
("de_AT", "German", "Austria"),
|
("de_AT", "German", "Austria"),
|
||||||
("de_CH", "German", "Switzerland"),
|
("de_CH", "German", "Switzerland"),
|
||||||
|
("de_DE", "German", "Germany"),
|
||||||
("el_GR", "Greek", "Greece"),
|
("el_GR", "Greek", "Greece"),
|
||||||
("en_AU", "English", "Australia"),
|
("en_AU", "English", "Australia"),
|
||||||
("en_CA", "English", "Canada"),
|
("en_CA", "English", "Canada"),
|
||||||
|
@ -58,10 +58,10 @@ language_codes = (
|
||||||
("ko_KR", "Korean", "Korea"),
|
("ko_KR", "Korean", "Korea"),
|
||||||
("lt_LT", "Lithuanian", "Lithuania"),
|
("lt_LT", "Lithuanian", "Lithuania"),
|
||||||
("lv_LV", "Latvian", "Latvia"),
|
("lv_LV", "Latvian", "Latvia"),
|
||||||
("oc_OC", "Occitan", "Occitan"),
|
|
||||||
("nb_NO", "Norwegian", "Norway"),
|
("nb_NO", "Norwegian", "Norway"),
|
||||||
("nl_BE", "Dutch", "Belgium"),
|
("nl_BE", "Dutch", "Belgium"),
|
||||||
("nl_NL", "Dutch", "Netherlands"),
|
("nl_NL", "Dutch", "Netherlands"),
|
||||||
|
("oc_OC", "Occitan", "Occitan"),
|
||||||
("pl_PL", "Polish", "Poland"),
|
("pl_PL", "Polish", "Poland"),
|
||||||
("pt_BR", "Portuguese", "Brazil"),
|
("pt_BR", "Portuguese", "Brazil"),
|
||||||
("pt_PT", "Portuguese", "Portugal"),
|
("pt_PT", "Portuguese", "Portugal"),
|
||||||
|
|
|
@ -28,12 +28,12 @@ import re
|
||||||
class Query(object):
|
class Query(object):
|
||||||
"""parse query"""
|
"""parse query"""
|
||||||
|
|
||||||
def __init__(self, query, blocked_engines):
|
def __init__(self, query, disabled_engines):
|
||||||
self.query = query
|
self.query = query
|
||||||
self.blocked_engines = []
|
self.disabled_engines = []
|
||||||
|
|
||||||
if blocked_engines:
|
if disabled_engines:
|
||||||
self.blocked_engines = blocked_engines
|
self.disabled_engines = disabled_engines
|
||||||
|
|
||||||
self.query_parts = []
|
self.query_parts = []
|
||||||
self.engines = []
|
self.engines = []
|
||||||
|
@ -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.name, prefix) not in self.blocked_engines)
|
if (engine.name, prefix) not in self.disabled_engines)
|
||||||
|
|
||||||
if query_part[0] == '!':
|
if query_part[0] == '!':
|
||||||
self.specific = True
|
self.specific = True
|
||||||
|
|
|
@ -140,7 +140,7 @@ class Search(object):
|
||||||
self.lang = 'all'
|
self.lang = 'all'
|
||||||
|
|
||||||
# set blocked engines
|
# set blocked engines
|
||||||
self.blocked_engines = request.preferences.engines.get_disabled()
|
self.disabled_engines = request.preferences.engines.get_disabled()
|
||||||
|
|
||||||
self.result_container = ResultContainer()
|
self.result_container = ResultContainer()
|
||||||
self.request_data = {}
|
self.request_data = {}
|
||||||
|
@ -167,7 +167,7 @@ class Search(object):
|
||||||
|
|
||||||
# parse query, if tags are set, which change
|
# parse query, if tags are set, which change
|
||||||
# the serch engine or search-language
|
# the serch engine or search-language
|
||||||
query_obj = Query(self.request_data['q'], self.blocked_engines)
|
query_obj = Query(self.request_data['q'], self.disabled_engines)
|
||||||
query_obj.parse_query()
|
query_obj.parse_query()
|
||||||
|
|
||||||
# set query
|
# set query
|
||||||
|
@ -227,8 +227,7 @@ class Search(object):
|
||||||
# using user-defined default-configuration which
|
# using user-defined default-configuration which
|
||||||
# (is stored in cookie)
|
# (is stored in cookie)
|
||||||
if not self.categories:
|
if not self.categories:
|
||||||
cookie_categories = request.cookies.get('categories', '')
|
cookie_categories = request.preferences.get_value('categories')
|
||||||
cookie_categories = cookie_categories.split(',')
|
|
||||||
for ccateg in cookie_categories:
|
for ccateg in cookie_categories:
|
||||||
if ccateg in categories:
|
if ccateg in categories:
|
||||||
self.categories.append(ccateg)
|
self.categories.append(ccateg)
|
||||||
|
@ -244,7 +243,7 @@ class Search(object):
|
||||||
self.engines.extend({'category': categ,
|
self.engines.extend({'category': categ,
|
||||||
'name': engine.name}
|
'name': engine.name}
|
||||||
for engine in categories[categ]
|
for engine in categories[categ]
|
||||||
if (engine.name, categ) not in self.blocked_engines)
|
if (engine.name, categ) not in self.disabled_engines)
|
||||||
|
|
||||||
# remove suspended engines
|
# remove suspended engines
|
||||||
self.engines = [e for e in self.engines
|
self.engines = [e for e in self.engines
|
||||||
|
|
|
@ -109,7 +109,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 }}__{{ categ }}"{% if (search_engine.name, categ) 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 disabled_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>
|
||||||
|
|
|
@ -97,7 +97,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 }}__{{ categ }}"{% if (search_engine.name, categ) 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 disabled_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>
|
||||||
|
|
|
@ -157,7 +157,7 @@
|
||||||
{% if not search_engine.private %}
|
{% if not search_engine.private %}
|
||||||
<tr>
|
<tr>
|
||||||
{% if not rtl %}
|
{% if not rtl %}
|
||||||
<td>{{ checkbox_toggle('engine_' + search_engine.name|replace(' ', '_') + '__' + categ|replace(' ', '_'), (search_engine.name, categ) in blocked_engines) }}</td>
|
<td>{{ checkbox_toggle('engine_' + search_engine.name|replace(' ', '_') + '__' + categ|replace(' ', '_'), (search_engine.name, categ) in disabled_engines) }}</td>
|
||||||
<th>{{ search_engine.name }}</th>
|
<th>{{ search_engine.name }}</th>
|
||||||
<td>{{ shortcuts[search_engine.name] }}</td>
|
<td>{{ shortcuts[search_engine.name] }}</td>
|
||||||
<td><input type="checkbox" {{ "checked" if search_engine.safesearch==True else ""}} readonly="readonly" disabled="disabled"></td>
|
<td><input type="checkbox" {{ "checked" if search_engine.safesearch==True else ""}} readonly="readonly" disabled="disabled"></td>
|
||||||
|
@ -169,7 +169,7 @@
|
||||||
<td><input type="checkbox" {{ "checked" if search_engine.safesearch==True else ""}} readonly="readonly" disabled="disabled"></td>
|
<td><input type="checkbox" {{ "checked" if search_engine.safesearch==True else ""}} readonly="readonly" disabled="disabled"></td>
|
||||||
<td>{{ shortcuts[search_engine.name] }}</td>
|
<td>{{ shortcuts[search_engine.name] }}</td>
|
||||||
<th>{{ search_engine.name }}</th>
|
<th>{{ search_engine.name }}</th>
|
||||||
<td>{{ checkbox_toggle('engine_' + search_engine.name|replace(' ', '_') + '__' + categ|replace(' ', '_'), (search_engine.name, categ) in blocked_engines) }}</td>
|
<td>{{ checkbox_toggle('engine_' + search_engine.name|replace(' ', '_') + '__' + categ|replace(' ', '_'), (search_engine.name, categ) in disabled_engines) }}</td>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</tr>
|
</tr>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
|
@ -60,7 +60,7 @@
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{ search_engine.name }} ({{ shortcuts[search_engine.name] }})‎</td>
|
<td>{{ search_engine.name }} ({{ shortcuts[search_engine.name] }})‎</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 }}__{{ categ }}"{% if (search_engine.name, categ) 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 disabled_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>
|
||||||
|
|
|
@ -74,7 +74,7 @@ try:
|
||||||
import pyasn1 # NOQA
|
import pyasn1 # NOQA
|
||||||
except ImportError:
|
except ImportError:
|
||||||
logger.critical("The pyopenssl, ndg-httpsclient, pyasn1 packages have to be installed.\n"
|
logger.critical("The pyopenssl, ndg-httpsclient, pyasn1 packages have to be installed.\n"
|
||||||
"Some HTTPS connections will failed")
|
"Some HTTPS connections will fail")
|
||||||
|
|
||||||
|
|
||||||
static_path, templates_path, themes =\
|
static_path, templates_path, themes =\
|
||||||
|
@ -110,6 +110,7 @@ for indice, theme in enumerate(themes):
|
||||||
for (dirpath, dirnames, filenames) in os.walk(theme_img_path):
|
for (dirpath, dirnames, filenames) in os.walk(theme_img_path):
|
||||||
global_favicons[indice].extend(filenames)
|
global_favicons[indice].extend(filenames)
|
||||||
|
|
||||||
|
# used when translating category names
|
||||||
_category_names = (gettext('files'),
|
_category_names = (gettext('files'),
|
||||||
gettext('general'),
|
gettext('general'),
|
||||||
gettext('music'),
|
gettext('music'),
|
||||||
|
@ -128,11 +129,8 @@ outgoing_proxies = settings['outgoing'].get('proxies', None)
|
||||||
def get_locale():
|
def get_locale():
|
||||||
locale = request.accept_languages.best_match(settings['locales'].keys())
|
locale = request.accept_languages.best_match(settings['locales'].keys())
|
||||||
|
|
||||||
if settings['ui'].get('default_locale'):
|
if request.preferences.get_value('locale') != '':
|
||||||
locale = settings['ui']['default_locale']
|
locale = request.preferences.get_value('locale')
|
||||||
|
|
||||||
if request.cookies.get('locale', '') in settings['locales']:
|
|
||||||
locale = request.cookies.get('locale', '')
|
|
||||||
|
|
||||||
if 'locale' in request.args\
|
if 'locale' in request.args\
|
||||||
and request.args['locale'] in settings['locales']:
|
and request.args['locale'] in settings['locales']:
|
||||||
|
@ -248,7 +246,7 @@ def image_proxify(url):
|
||||||
if url.startswith('//'):
|
if url.startswith('//'):
|
||||||
url = 'https:' + url
|
url = 'https:' + url
|
||||||
|
|
||||||
if not settings['server'].get('image_proxy') and not request.cookies.get('image_proxy'):
|
if not request.preferences.get_value('image_proxy'):
|
||||||
return url
|
return url
|
||||||
|
|
||||||
hash_string = url + settings['server']['secret_key']
|
hash_string = url + settings['server']['secret_key']
|
||||||
|
@ -259,19 +257,18 @@ def image_proxify(url):
|
||||||
|
|
||||||
|
|
||||||
def render(template_name, override_theme=None, **kwargs):
|
def render(template_name, override_theme=None, **kwargs):
|
||||||
blocked_engines = request.preferences.engines.get_disabled()
|
disabled_engines = request.preferences.engines.get_disabled()
|
||||||
autocomplete = request.preferences.get_value('autocomplete')
|
|
||||||
|
|
||||||
nonblocked_categories = set(category for engine_name in engines
|
enabled_categories = set(category for engine_name in engines
|
||||||
for category in engines[engine_name].categories
|
for category in engines[engine_name].categories
|
||||||
if (engine_name, category) not in blocked_engines)
|
if (engine_name, category) not in disabled_engines)
|
||||||
|
|
||||||
if 'categories' not in kwargs:
|
if 'categories' not in kwargs:
|
||||||
kwargs['categories'] = ['general']
|
kwargs['categories'] = ['general']
|
||||||
kwargs['categories'].extend(x for x in
|
kwargs['categories'].extend(x for x in
|
||||||
sorted(categories.keys())
|
sorted(categories.keys())
|
||||||
if x != 'general'
|
if x != 'general'
|
||||||
and x in nonblocked_categories)
|
and x in enabled_categories)
|
||||||
|
|
||||||
if 'all_categories' not in kwargs:
|
if 'all_categories' not in kwargs:
|
||||||
kwargs['all_categories'] = ['general']
|
kwargs['all_categories'] = ['general']
|
||||||
|
@ -290,14 +287,13 @@ def render(template_name, override_theme=None, **kwargs):
|
||||||
if not kwargs['selected_categories']:
|
if not kwargs['selected_categories']:
|
||||||
cookie_categories = request.preferences.get_value('categories')
|
cookie_categories = request.preferences.get_value('categories')
|
||||||
for ccateg in cookie_categories:
|
for ccateg in cookie_categories:
|
||||||
if ccateg in categories:
|
|
||||||
kwargs['selected_categories'].append(ccateg)
|
kwargs['selected_categories'].append(ccateg)
|
||||||
|
|
||||||
if not kwargs['selected_categories']:
|
if not kwargs['selected_categories']:
|
||||||
kwargs['selected_categories'] = ['general']
|
kwargs['selected_categories'] = ['general']
|
||||||
|
|
||||||
if 'autocomplete' not in kwargs:
|
if 'autocomplete' not in kwargs:
|
||||||
kwargs['autocomplete'] = autocomplete
|
kwargs['autocomplete'] = request.preferences.get_value('autocomplete')
|
||||||
|
|
||||||
if get_locale() in rtl_locales and 'rtl' not in kwargs:
|
if get_locale() in rtl_locales and 'rtl' not in kwargs:
|
||||||
kwargs['rtl'] = True
|
kwargs['rtl'] = True
|
||||||
|
@ -483,10 +479,10 @@ def autocompleter():
|
||||||
request_data = request.args
|
request_data = request.args
|
||||||
|
|
||||||
# set blocked engines
|
# set blocked engines
|
||||||
blocked_engines = request.preferences.engines.get_disabled()
|
disabled_engines = request.preferences.engines.get_disabled()
|
||||||
|
|
||||||
# parse query
|
# parse query
|
||||||
query = Query(request_data.get('q', '').encode('utf-8'), blocked_engines)
|
query = Query(request_data.get('q', '').encode('utf-8'), disabled_engines)
|
||||||
query.parse_query()
|
query.parse_query()
|
||||||
|
|
||||||
# check if search query is set
|
# check if search query is set
|
||||||
|
@ -502,7 +498,7 @@ def autocompleter():
|
||||||
# normal autocompletion results only appear if max 3 inner results returned
|
# normal autocompletion results only appear if max 3 inner results returned
|
||||||
if len(raw_results) <= 3 and completer:
|
if len(raw_results) <= 3 and completer:
|
||||||
# get language from cookie
|
# get language from cookie
|
||||||
language = request.cookies.get('language')
|
language = request.preferences.get_value('language')
|
||||||
if not language or language == 'all':
|
if not language or language == 'all':
|
||||||
language = 'en'
|
language = 'en'
|
||||||
else:
|
else:
|
||||||
|
@ -544,7 +540,7 @@ def preferences():
|
||||||
# render preferences
|
# render preferences
|
||||||
image_proxy = request.preferences.get_value('image_proxy')
|
image_proxy = request.preferences.get_value('image_proxy')
|
||||||
lang = request.preferences.get_value('language')
|
lang = request.preferences.get_value('language')
|
||||||
blocked_engines = request.preferences.engines.get_disabled()
|
disabled_engines = request.preferences.engines.get_disabled()
|
||||||
allowed_plugins = request.preferences.plugins.get_enabled()
|
allowed_plugins = request.preferences.plugins.get_enabled()
|
||||||
|
|
||||||
# stats for preferences page
|
# stats for preferences page
|
||||||
|
@ -572,7 +568,7 @@ def preferences():
|
||||||
language_codes=language_codes,
|
language_codes=language_codes,
|
||||||
engines_by_category=categories,
|
engines_by_category=categories,
|
||||||
stats=stats,
|
stats=stats,
|
||||||
blocked_engines=blocked_engines,
|
disabled_engines=disabled_engines,
|
||||||
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,
|
||||||
|
|
Loading…
Reference in New Issue