From 1805cfd20a7b11e7c3c5c4c03b4e3755e09d783d Mon Sep 17 00:00:00 2001 From: Noemi Vanyi Date: Mon, 28 Mar 2016 23:59:59 +0200 Subject: [PATCH 1/6] sort languages properly --- searx/languages.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/searx/languages.py b/searx/languages.py index b67da9d22..70459a577 100644 --- a/searx/languages.py +++ b/searx/languages.py @@ -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"), From 006841c4ff481b023dccd188582a9cbac64415da Mon Sep 17 00:00:00 2001 From: Noemi Vanyi Date: Sat, 9 Apr 2016 14:46:02 +0200 Subject: [PATCH 2/6] minor grammar fix in error message --- searx/webapp.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/searx/webapp.py b/searx/webapp.py index 7f0b56101..5b15c43d1 100644 --- a/searx/webapp.py +++ b/searx/webapp.py @@ -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 =\ From 8c4db08443c7a55344fa0011b89303467fa62efe Mon Sep 17 00:00:00 2001 From: Noemi Vanyi Date: Sat, 9 Apr 2016 18:26:29 +0200 Subject: [PATCH 3/6] rename blocked engines to diabled engines --- searx/query.py | 10 +++++----- searx/search.py | 6 +++--- searx/webapp.py | 19 +++++++++---------- 3 files changed, 17 insertions(+), 18 deletions(-) diff --git a/searx/query.py b/searx/query.py index e79e760a3..3d617ab05 100644 --- a/searx/query.py +++ b/searx/query.py @@ -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 diff --git a/searx/search.py b/searx/search.py index f38d40106..215774c06 100644 --- a/searx/search.py +++ b/searx/search.py @@ -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 @@ -244,7 +244,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 diff --git a/searx/webapp.py b/searx/webapp.py index 5b15c43d1..1420906f5 100644 --- a/searx/webapp.py +++ b/searx/webapp.py @@ -259,19 +259,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'] @@ -483,10 +482,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 @@ -544,7 +543,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 +571,7 @@ def preferences(): language_codes=language_codes, engines_by_category=categories, stats=stats, - blocked_engines=blocked_engines, + blocked_engines=disabled_engines, autocomplete_backends=autocomplete_backends, shortcuts={y: x for x, y in engine_shortcuts.items()}, themes=themes, From 5867e979664d655616e09b74b81fb099a2504ba8 Mon Sep 17 00:00:00 2001 From: Noemi Vanyi Date: Sat, 9 Apr 2016 18:32:07 +0200 Subject: [PATCH 4/6] more follow ups in new preferences --- searx/search.py | 3 +-- searx/webapp.py | 16 ++++++---------- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/searx/search.py b/searx/search.py index 215774c06..a40801640 100644 --- a/searx/search.py +++ b/searx/search.py @@ -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) diff --git a/searx/webapp.py b/searx/webapp.py index 1420906f5..e4e99de62 100644 --- a/searx/webapp.py +++ b/searx/webapp.py @@ -128,11 +128,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 +245,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'] @@ -289,14 +286,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 @@ -501,7 +497,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: From 7daf98933d39151ab5fd7929645f26497db8b8af Mon Sep 17 00:00:00 2001 From: Noemi Vanyi Date: Sat, 9 Apr 2016 18:48:23 +0200 Subject: [PATCH 5/6] follow up blocked_engines renaming in templates --- searx/templates/courgette/preferences.html | 2 +- searx/templates/default/preferences.html | 2 +- searx/templates/oscar/preferences.html | 4 ++-- searx/templates/pix-art/preferences.html | 2 +- searx/webapp.py | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/searx/templates/courgette/preferences.html b/searx/templates/courgette/preferences.html index f89915d8d..ba4d0c650 100644 --- a/searx/templates/courgette/preferences.html +++ b/searx/templates/courgette/preferences.html @@ -109,7 +109,7 @@ {{ search_engine.name }} ({{ shortcuts[search_engine.name] }})‎ {{ _(categ) }} - + diff --git a/searx/templates/default/preferences.html b/searx/templates/default/preferences.html index 90006c029..a47dba458 100644 --- a/searx/templates/default/preferences.html +++ b/searx/templates/default/preferences.html @@ -97,7 +97,7 @@ {{ search_engine.name }} ({{ shortcuts[search_engine.name] }})‎ {{ _(categ) }} - + diff --git a/searx/templates/oscar/preferences.html b/searx/templates/oscar/preferences.html index c677a0c66..a2c493a02 100644 --- a/searx/templates/oscar/preferences.html +++ b/searx/templates/oscar/preferences.html @@ -157,7 +157,7 @@ {% if not search_engine.private %} {% if not rtl %} - {{ checkbox_toggle('engine_' + search_engine.name|replace(' ', '_') + '__' + categ|replace(' ', '_'), (search_engine.name, categ) in blocked_engines) }} + {{ checkbox_toggle('engine_' + search_engine.name|replace(' ', '_') + '__' + categ|replace(' ', '_'), (search_engine.name, categ) in disabled_engines) }} {{ search_engine.name }} {{ shortcuts[search_engine.name] }} @@ -169,7 +169,7 @@ {{ shortcuts[search_engine.name] }} {{ search_engine.name }} - {{ checkbox_toggle('engine_' + search_engine.name|replace(' ', '_') + '__' + categ|replace(' ', '_'), (search_engine.name, categ) in blocked_engines) }} + {{ checkbox_toggle('engine_' + search_engine.name|replace(' ', '_') + '__' + categ|replace(' ', '_'), (search_engine.name, categ) in disabled_engines) }} {% endif %} {% endif %} diff --git a/searx/templates/pix-art/preferences.html b/searx/templates/pix-art/preferences.html index f59497ec8..a4a6cd268 100644 --- a/searx/templates/pix-art/preferences.html +++ b/searx/templates/pix-art/preferences.html @@ -60,7 +60,7 @@ {{ search_engine.name }} ({{ shortcuts[search_engine.name] }})‎ - + diff --git a/searx/webapp.py b/searx/webapp.py index e4e99de62..e05a08a2f 100644 --- a/searx/webapp.py +++ b/searx/webapp.py @@ -567,7 +567,7 @@ def preferences(): language_codes=language_codes, engines_by_category=categories, stats=stats, - blocked_engines=disabled_engines, + disabled_engines=disabled_engines, autocomplete_backends=autocomplete_backends, shortcuts={y: x for x, y in engine_shortcuts.items()}, themes=themes, From adb1169fa31b6c504a3f99123d711b3f5c4bf070 Mon Sep 17 00:00:00 2001 From: Noemi Vanyi Date: Sat, 9 Apr 2016 19:47:06 +0200 Subject: [PATCH 6/6] add description to a var that seems to be unused --- searx/webapp.py | 1 + 1 file changed, 1 insertion(+) diff --git a/searx/webapp.py b/searx/webapp.py index e05a08a2f..ed8ff1bd9 100644 --- a/searx/webapp.py +++ b/searx/webapp.py @@ -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'),