mirror of
https://github.com/searxng/searxng.git
synced 2024-08-23 22:50:26 +02:00
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"),
|
||||
("bg_BG", "Bulgarian", "Bulgaria"),
|
||||
("cs_CZ", "Czech", "Czech Republic"),
|
||||
("de_DE", "German", "Germany"),
|
||||
("da_DK", "Danish", "Denmark"),
|
||||
("de_AT", "German", "Austria"),
|
||||
("de_CH", "German", "Switzerland"),
|
||||
("de_DE", "German", "Germany"),
|
||||
("el_GR", "Greek", "Greece"),
|
||||
("en_AU", "English", "Australia"),
|
||||
("en_CA", "English", "Canada"),
|
||||
@ -58,10 +58,10 @@ language_codes = (
|
||||
("ko_KR", "Korean", "Korea"),
|
||||
("lt_LT", "Lithuanian", "Lithuania"),
|
||||
("lv_LV", "Latvian", "Latvia"),
|
||||
("oc_OC", "Occitan", "Occitan"),
|
||||
("nb_NO", "Norwegian", "Norway"),
|
||||
("nl_BE", "Dutch", "Belgium"),
|
||||
("nl_NL", "Dutch", "Netherlands"),
|
||||
("oc_OC", "Occitan", "Occitan"),
|
||||
("pl_PL", "Polish", "Poland"),
|
||||
("pt_BR", "Portuguese", "Brazil"),
|
||||
("pt_PT", "Portuguese", "Portugal"),
|
||||
|
@ -28,12 +28,12 @@ import re
|
||||
class Query(object):
|
||||
"""parse query"""
|
||||
|
||||
def __init__(self, query, blocked_engines):
|
||||
def __init__(self, query, disabled_engines):
|
||||
self.query = query
|
||||
self.blocked_engines = []
|
||||
self.disabled_engines = []
|
||||
|
||||
if blocked_engines:
|
||||
self.blocked_engines = blocked_engines
|
||||
if disabled_engines:
|
||||
self.disabled_engines = disabled_engines
|
||||
|
||||
self.query_parts = []
|
||||
self.engines = []
|
||||
@ -107,7 +107,7 @@ class Query(object):
|
||||
self.engines.extend({'category': prefix,
|
||||
'name': engine.name}
|
||||
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] == '!':
|
||||
self.specific = True
|
||||
|
@ -140,7 +140,7 @@ class Search(object):
|
||||
self.lang = 'all'
|
||||
|
||||
# set blocked engines
|
||||
self.blocked_engines = request.preferences.engines.get_disabled()
|
||||
self.disabled_engines = request.preferences.engines.get_disabled()
|
||||
|
||||
self.result_container = ResultContainer()
|
||||
self.request_data = {}
|
||||
@ -167,7 +167,7 @@ class Search(object):
|
||||
|
||||
# parse query, if tags are set, which change
|
||||
# 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()
|
||||
|
||||
# set query
|
||||
@ -227,8 +227,7 @@ class Search(object):
|
||||
# using user-defined default-configuration which
|
||||
# (is stored in cookie)
|
||||
if not self.categories:
|
||||
cookie_categories = request.cookies.get('categories', '')
|
||||
cookie_categories = cookie_categories.split(',')
|
||||
cookie_categories = request.preferences.get_value('categories')
|
||||
for ccateg in cookie_categories:
|
||||
if ccateg in categories:
|
||||
self.categories.append(ccateg)
|
||||
@ -244,7 +243,7 @@ class Search(object):
|
||||
self.engines.extend({'category': categ,
|
||||
'name': engine.name}
|
||||
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
|
||||
self.engines = [e for e in self.engines
|
||||
|
@ -109,7 +109,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 }}__{{ 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="deny" for="engine_{{ categ|replace(' ', '_') }}_{{ search_engine.name|replace(' ', '_') }}">{{ _('Block') }}</label>
|
||||
</td>
|
||||
|
@ -97,7 +97,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 }}__{{ 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="deny" for="engine_{{ categ|replace(' ', '_') }}_{{ search_engine.name|replace(' ', '_') }}">{{ _('Block') }}</label>
|
||||
</td>
|
||||
|
@ -157,7 +157,7 @@
|
||||
{% if not search_engine.private %}
|
||||
<tr>
|
||||
{% 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>
|
||||
<td>{{ shortcuts[search_engine.name] }}</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>{{ shortcuts[search_engine.name] }}</td>
|
||||
<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 %}
|
||||
</tr>
|
||||
{% endif %}
|
||||
|
@ -60,7 +60,7 @@
|
||||
<tr>
|
||||
<td>{{ search_engine.name }} ({{ shortcuts[search_engine.name] }})‎</td>
|
||||
<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="deny" for="engine_{{ categ|replace(' ', '_') }}_{{ search_engine.name|replace(' ', '_') }}">{{ _('Block') }}</label>
|
||||
</td>
|
||||
|
@ -74,7 +74,7 @@ try:
|
||||
import pyasn1 # NOQA
|
||||
except ImportError:
|
||||
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 =\
|
||||
@ -110,6 +110,7 @@ for indice, theme in enumerate(themes):
|
||||
for (dirpath, dirnames, filenames) in os.walk(theme_img_path):
|
||||
global_favicons[indice].extend(filenames)
|
||||
|
||||
# used when translating category names
|
||||
_category_names = (gettext('files'),
|
||||
gettext('general'),
|
||||
gettext('music'),
|
||||
@ -128,11 +129,8 @@ outgoing_proxies = settings['outgoing'].get('proxies', None)
|
||||
def get_locale():
|
||||
locale = request.accept_languages.best_match(settings['locales'].keys())
|
||||
|
||||
if settings['ui'].get('default_locale'):
|
||||
locale = settings['ui']['default_locale']
|
||||
|
||||
if request.cookies.get('locale', '') in settings['locales']:
|
||||
locale = request.cookies.get('locale', '')
|
||||
if request.preferences.get_value('locale') != '':
|
||||
locale = request.preferences.get_value('locale')
|
||||
|
||||
if 'locale' in request.args\
|
||||
and request.args['locale'] in settings['locales']:
|
||||
@ -248,7 +246,7 @@ def image_proxify(url):
|
||||
if url.startswith('//'):
|
||||
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
|
||||
|
||||
hash_string = url + settings['server']['secret_key']
|
||||
@ -259,19 +257,18 @@ def image_proxify(url):
|
||||
|
||||
|
||||
def render(template_name, override_theme=None, **kwargs):
|
||||
blocked_engines = request.preferences.engines.get_disabled()
|
||||
autocomplete = request.preferences.get_value('autocomplete')
|
||||
disabled_engines = request.preferences.engines.get_disabled()
|
||||
|
||||
nonblocked_categories = set(category for engine_name in engines
|
||||
for category in engines[engine_name].categories
|
||||
if (engine_name, category) not in blocked_engines)
|
||||
enabled_categories = set(category for engine_name in engines
|
||||
for category in engines[engine_name].categories
|
||||
if (engine_name, category) not in disabled_engines)
|
||||
|
||||
if 'categories' not in kwargs:
|
||||
kwargs['categories'] = ['general']
|
||||
kwargs['categories'].extend(x for x in
|
||||
sorted(categories.keys())
|
||||
if x != 'general'
|
||||
and x in nonblocked_categories)
|
||||
and x in enabled_categories)
|
||||
|
||||
if 'all_categories' not in kwargs:
|
||||
kwargs['all_categories'] = ['general']
|
||||
@ -290,14 +287,13 @@ def render(template_name, override_theme=None, **kwargs):
|
||||
if not kwargs['selected_categories']:
|
||||
cookie_categories = request.preferences.get_value('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']:
|
||||
kwargs['selected_categories'] = ['general']
|
||||
|
||||
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:
|
||||
kwargs['rtl'] = True
|
||||
@ -483,10 +479,10 @@ def autocompleter():
|
||||
request_data = request.args
|
||||
|
||||
# set blocked engines
|
||||
blocked_engines = request.preferences.engines.get_disabled()
|
||||
disabled_engines = request.preferences.engines.get_disabled()
|
||||
|
||||
# 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()
|
||||
|
||||
# check if search query is set
|
||||
@ -502,7 +498,7 @@ def autocompleter():
|
||||
# normal autocompletion results only appear if max 3 inner results returned
|
||||
if len(raw_results) <= 3 and completer:
|
||||
# get language from cookie
|
||||
language = request.cookies.get('language')
|
||||
language = request.preferences.get_value('language')
|
||||
if not language or language == 'all':
|
||||
language = 'en'
|
||||
else:
|
||||
@ -544,7 +540,7 @@ def preferences():
|
||||
# render preferences
|
||||
image_proxy = request.preferences.get_value('image_proxy')
|
||||
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()
|
||||
|
||||
# stats for preferences page
|
||||
@ -572,7 +568,7 @@ def preferences():
|
||||
language_codes=language_codes,
|
||||
engines_by_category=categories,
|
||||
stats=stats,
|
||||
blocked_engines=blocked_engines,
|
||||
disabled_engines=disabled_engines,
|
||||
autocomplete_backends=autocomplete_backends,
|
||||
shortcuts={y: x for x, y in engine_shortcuts.items()},
|
||||
themes=themes,
|
||||
|
Loading…
Reference in New Issue
Block a user