From a818d3241df2cf010086f837a504b11983c3d55f Mon Sep 17 00:00:00 2001 From: Nicolas Gelot Date: Thu, 28 Mar 2019 18:07:02 +0100 Subject: Remove get local from request.args args parameters are merged in form in pre_request, so this patch removes that useless operation. --- searx/webapp.py | 4 ---- 1 file changed, 4 deletions(-) (limited to 'searx/webapp.py') diff --git a/searx/webapp.py b/searx/webapp.py index 727259774..c44612a44 100644 --- a/searx/webapp.py +++ b/searx/webapp.py @@ -157,10 +157,6 @@ def 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']: - locale = request.args['locale'] - if 'locale' in request.form\ and request.form['locale'] in settings['locales']: locale = request.form['locale'] -- cgit v1.2.3 From 373a66be3046bbb7deca20f08468cb5dea44eaf9 Mon Sep 17 00:00:00 2001 From: Nicolas Gelot Date: Thu, 28 Mar 2019 18:07:03 +0100 Subject: Fix locale and search language Locale and search language was always defined with english value. This patch inits the locale on `pre_request` in order to define the default value of locale and language preferences. Plus the `best_match` function provided by flask babel library did not work as expected. So the function `match_language` provided by searx is used to detect that the language from Accepted-Language header can be used in searx project. --- searx/webapp.py | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) (limited to 'searx/webapp.py') diff --git a/searx/webapp.py b/searx/webapp.py index c44612a44..542c2c002 100644 --- a/searx/webapp.py +++ b/searx/webapp.py @@ -152,7 +152,14 @@ outgoing_proxies = settings['outgoing'].get('proxies') or None @babel.localeselector def get_locale(): - locale = request.accept_languages.best_match(settings['locales'].keys()) + locale = "en-US" + + for lang in request.headers.get("Accept-Language", locale).split(","): + locale = match_language(lang, settings['locales'].keys(), fallback=None) + if locale is not None: + break + + logger.debug("default locale from browser info is `%s`", locale) if request.preferences.get_value('locale') != '': locale = request.preferences.get_value('locale') @@ -164,6 +171,8 @@ def get_locale(): if locale == 'zh_TW': locale = 'zh_Hant_TW' + logger.debug("selected locale is `%s`", locale) + return locale @@ -342,7 +351,9 @@ def render(template_name, override_theme=None, **kwargs): if 'autocomplete' not in kwargs: kwargs['autocomplete'] = request.preferences.get_value('autocomplete') - if get_locale() in rtl_locales and 'rtl' not in kwargs: + locale = request.preferences.get_value('locale') + + if locale in rtl_locales and 'rtl' not in kwargs: kwargs['rtl'] = True kwargs['searx_version'] = VERSION_STRING @@ -355,7 +366,7 @@ def render(template_name, override_theme=None, **kwargs): if 'current_language' not in kwargs: kwargs['current_language'] = match_language(request.preferences.get_value('language'), LANGUAGE_CODES, - fallback=settings['search']['language']) + fallback=locale) # override url_for function in templates kwargs['url_for'] = url_for_theme @@ -423,6 +434,13 @@ def pre_request(): logger.exception('invalid settings') request.errors.append(gettext('Invalid settings')) + # init search language and locale + locale = get_locale() + if not preferences.get_value("language"): + preferences.parse_dict({"language": locale}) + if not preferences.get_value("locale"): + preferences.parse_dict({"locale": locale}) + # request.user_plugins request.user_plugins = [] allowed_plugins = preferences.plugins.get_enabled() @@ -593,7 +611,7 @@ def index(): unresponsive_engines=result_container.unresponsive_engines, current_language=match_language(search_query.lang, LANGUAGE_CODES, - fallback=settings['search']['language']), + fallback=request.preferences.get_value("language")), base_url=get_base_url(), theme=get_current_theme_name(), favicons=global_favicons[themes.index(get_current_theme_name())] @@ -702,7 +720,7 @@ def preferences(): return render('preferences.html', locales=settings['locales'], - current_locale=get_locale(), + current_locale=request.preferences.get_value("locale"), image_proxy=image_proxy, engines_by_category=categories, stats=stats, -- cgit v1.2.3 From 495ae59b31b6aafae484ecdfb6aece3a84f1ede7 Mon Sep 17 00:00:00 2001 From: Marc Abonce Seguin Date: Sun, 25 Aug 2019 23:01:30 -0700 Subject: hide suggestions box if empty This bug happens only in python3 because map returns an iterator. --- searx/webapp.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'searx/webapp.py') diff --git a/searx/webapp.py b/searx/webapp.py index 7cf4106d3..212c874c9 100644 --- a/searx/webapp.py +++ b/searx/webapp.py @@ -606,11 +606,11 @@ def index(): # HTML output format # suggestions: use RawTextQuery to get the suggestion URLs with the same bang - suggestion_urls = map(lambda suggestion: { - 'url': raw_text_query.changeSearchQuery(suggestion).getFullQuery(), - 'title': suggestion - }, - result_container.suggestions) + suggestion_urls = list(map(lambda suggestion: { + 'url': raw_text_query.changeSearchQuery(suggestion).getFullQuery(), + 'title': suggestion + }, + result_container.suggestions)) correction_urls = list(map(lambda correction: { 'url': raw_text_query.changeSearchQuery(correction).getFullQuery(), -- cgit v1.2.3 From 8e3bd3fcbd3a075f4c7edbd0175ae3dc5a87da53 Mon Sep 17 00:00:00 2001 From: Adam Tauber Date: Tue, 28 Jan 2020 15:52:50 +0100 Subject: [mod] add py2 deprecation warning to webapp --- searx/webapp.py | 2 ++ 1 file changed, 2 insertions(+) (limited to 'searx/webapp.py') diff --git a/searx/webapp.py b/searx/webapp.py index 212c874c9..aadefe6b9 100644 --- a/searx/webapp.py +++ b/searx/webapp.py @@ -95,6 +95,8 @@ if sys.version_info[0] == 3: PY3 = True else: PY3 = False + logger.warning('\033[1;31m *** Deprecation Warning ***\033[0m') + logger.warning('\033[1;31m Python2 is deprecated\033[0m') # serve pages with HTTP/1.1 from werkzeug.serving import WSGIRequestHandler -- cgit v1.2.3 From b8b13372c8fd3bfe978a1c724ab98b05348df054 Mon Sep 17 00:00:00 2001 From: Nicolas Gelot Date: Thu, 6 Feb 2020 22:40:58 +0100 Subject: Fix deprecated werkzeug import Close: #1830 Signed-off-by: Nicolas Gelot --- searx/webapp.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'searx/webapp.py') diff --git a/searx/webapp.py b/searx/webapp.py index aadefe6b9..5ed9f1277 100644 --- a/searx/webapp.py +++ b/searx/webapp.py @@ -47,7 +47,7 @@ except: from html import escape from datetime import datetime, timedelta from time import time -from werkzeug.contrib.fixers import ProxyFix +from werkzeug.middleware.proxy_fix import ProxyFix from flask import ( Flask, request, render_template, url_for, Response, make_response, redirect, send_from_directory -- cgit v1.2.3 From 99435381a84072b110c32004b2fb778af9b96f77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?No=C3=A9mi=20V=C3=A1nyi?= Date: Sat, 1 Feb 2020 11:01:17 +0100 Subject: [enh] introduce private engines This PR adds a new setting to engines named `tokens`. It expects a list of tokens which lets searx validate if the request should be accepted or not. --- searx/webapp.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'searx/webapp.py') diff --git a/searx/webapp.py b/searx/webapp.py index 5ed9f1277..fd34a9ef4 100644 --- a/searx/webapp.py +++ b/searx/webapp.py @@ -731,8 +731,13 @@ def preferences(): # stats for preferences page stats = {} + engines_by_category = {} for c in categories: + engines_by_category[c] = [] for e in categories[c]: + if not request.preferences.validate_token(e): + continue + stats[e.name] = {'time': None, 'warn_timeout': False, 'warn_time': False} @@ -740,9 +745,11 @@ def preferences(): stats[e.name]['warn_timeout'] = True stats[e.name]['supports_selected_language'] = _is_selected_language_supported(e, request.preferences) + engines_by_category[c].append(e) + # get first element [0], the engine time, # and then the second element [1] : the time (the first one is the label) - for engine_stat in get_engines_stats()[0][1]: + for engine_stat in get_engines_stats(request.preferences)[0][1]: stats[engine_stat.get('name')]['time'] = round(engine_stat.get('avg'), 3) if engine_stat.get('avg') > settings['outgoing']['request_timeout']: stats[engine_stat.get('name')]['warn_time'] = True @@ -752,7 +759,7 @@ def preferences(): locales=settings['locales'], current_locale=get_locale(), image_proxy=image_proxy, - engines_by_category=categories, + engines_by_category=engines_by_category, stats=stats, answerers=[{'info': a.self_info(), 'keywords': a.keywords} for a in answerers], disabled_engines=disabled_engines, @@ -828,7 +835,7 @@ def image_proxy(): @app.route('/stats', methods=['GET']) def stats(): """Render engine statistics page.""" - stats = get_engines_stats() + stats = get_engines_stats(request.preferences) return render( 'stats.html', stats=stats, @@ -891,7 +898,7 @@ def clear_cookies(): @app.route('/config') def config(): return jsonify({'categories': list(categories.keys()), - 'engines': [{'name': engine_name, + 'engines': [{'name': name, 'categories': engine.categories, 'shortcut': engine.shortcut, 'enabled': not engine.disabled, @@ -904,7 +911,7 @@ def config(): 'safesearch': engine.safesearch, 'time_range_support': engine.time_range_support, 'timeout': engine.timeout} - for engine_name, engine in engines.items()], + for name, engine in engines.items() if request.preferences.validate_token(engine)], 'plugins': [{'name': plugin.name, 'enabled': plugin.default_on} for plugin in plugins], -- cgit v1.2.3 From c0006cadf70f0ee457d881bbd4ec40e30b0acd8f Mon Sep 17 00:00:00 2001 From: Marc Abonce Seguin Date: Sun, 23 Feb 2020 02:03:42 -0700 Subject: fix default locale and language issues --- searx/webapp.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'searx/webapp.py') diff --git a/searx/webapp.py b/searx/webapp.py index a856c07dd..8712cc3c1 100644 --- a/searx/webapp.py +++ b/searx/webapp.py @@ -157,14 +157,16 @@ _category_names = (gettext('files'), outgoing_proxies = settings['outgoing'].get('proxies') or None +def _get_browser_language(request, lang_list): + for lang in request.headers.get("Accept-Language", "en").split(","): + locale = match_language(lang, lang_list, fallback=None) + if locale is not None: + return locale + + @babel.localeselector def get_locale(): - locale = "en-US" - - for lang in request.headers.get("Accept-Language", locale).split(","): - locale = match_language(lang, settings['locales'].keys(), fallback=None) - if locale is not None: - break + locale = _get_browser_language(request, settings['locales'].keys()) logger.debug("default locale from browser info is `%s`", locale) @@ -372,8 +374,7 @@ def render(template_name, override_theme=None, **kwargs): kwargs['language_codes'] = languages if 'current_language' not in kwargs: kwargs['current_language'] = match_language(request.preferences.get_value('language'), - LANGUAGE_CODES, - fallback=locale) + LANGUAGE_CODES) # override url_for function in templates kwargs['url_for'] = url_for_theme @@ -444,11 +445,10 @@ def pre_request(): request.errors.append(gettext('Invalid settings')) # init search language and locale - locale = get_locale() if not preferences.get_value("language"): - preferences.parse_dict({"language": locale}) + preferences.parse_dict({"language": _get_browser_language(request, LANGUAGE_CODES)}) if not preferences.get_value("locale"): - preferences.parse_dict({"locale": locale}) + preferences.parse_dict({"locale": get_locale()}) # request.user_plugins request.user_plugins = [] -- cgit v1.2.3 From 51e78211de5b1fcec818be089631e778bd136fc9 Mon Sep 17 00:00:00 2001 From: Marc Abonce Seguin Date: Sun, 23 Feb 2020 21:46:26 -0700 Subject: monkey patch babel get_translations to support Occitan --- searx/webapp.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'searx/webapp.py') diff --git a/searx/webapp.py b/searx/webapp.py index 8712cc3c1..b661e39d1 100644 --- a/searx/webapp.py +++ b/searx/webapp.py @@ -45,6 +45,7 @@ try: from cgi import escape except: from html import escape +from six import next from datetime import datetime, timedelta from time import time from werkzeug.middleware.proxy_fix import ProxyFix @@ -52,6 +53,8 @@ from flask import ( Flask, request, render_template, url_for, Response, make_response, redirect, send_from_directory ) +from babel.support import Translations +import flask_babel from flask_babel import Babel, gettext, format_date, format_decimal from flask.json import jsonify from searx import settings, searx_dir, searx_debug @@ -156,6 +159,22 @@ _category_names = (gettext('files'), outgoing_proxies = settings['outgoing'].get('proxies') or None +_flask_babel_get_translations = flask_babel.get_translations + + +# monkey patch for flask_babel.get_translations +def _get_translations(): + translation_locale = request.form.get('use-translation') + if translation_locale: + babel_ext = flask_babel.current_app.extensions['babel'] + translation = Translations.load(next(babel_ext.translation_directories), 'oc') + else: + translation = _flask_babel_get_translations() + return translation + + +flask_babel.get_translations = _get_translations + def _get_browser_language(request, lang_list): for lang in request.headers.get("Accept-Language", "en").split(","): @@ -180,6 +199,10 @@ def get_locale(): if locale == 'zh_TW': locale = 'zh_Hant_TW' + if locale == 'oc': + request.form['use-translation'] = 'oc' + locale = 'fr_FR' + logger.debug("selected locale is `%s`", locale) return locale -- cgit v1.2.3 From 9bc24080bf4c24a182cf2b5616095c2f6bea5821 Mon Sep 17 00:00:00 2001 From: Adam Tauber Date: Fri, 13 Mar 2020 00:43:05 +0100 Subject: [fix] add answers, suggestions, corrections to rss output fixes #1888 --- searx/webapp.py | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'searx/webapp.py') diff --git a/searx/webapp.py b/searx/webapp.py index b661e39d1..da2bf34a9 100644 --- a/searx/webapp.py +++ b/searx/webapp.py @@ -637,9 +637,13 @@ def index(): response.headers.add('Content-Disposition', cont_disp) return response elif output_format == 'rss': + print(results) response_rss = render( 'opensearch_response_rss.xml', results=results, + answers=result_container.answers, + corrections=result_container.corrections, + suggestions=result_container.suggestions, q=request.form['q'], number_of_results=number_of_results, base_url=get_base_url(), -- cgit v1.2.3 From 018b6818419a1c3044b7d7244b55a62779063071 Mon Sep 17 00:00:00 2001 From: Adam Tauber Date: Fri, 13 Mar 2020 00:50:19 +0100 Subject: [fix] add answers, suggestions, corrections to csv output fixes #1888 --- searx/webapp.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'searx/webapp.py') diff --git a/searx/webapp.py b/searx/webapp.py index da2bf34a9..49129d14e 100644 --- a/searx/webapp.py +++ b/searx/webapp.py @@ -626,10 +626,20 @@ def index(): mimetype='application/json') elif output_format == 'csv': csv = UnicodeWriter(StringIO()) - keys = ('title', 'url', 'content', 'host', 'engine', 'score') + keys = ('title', 'url', 'content', 'host', 'engine', 'score', 'type') csv.writerow(keys) for row in results: row['host'] = row['parsed_url'].netloc + row['type'] = 'result' + csv.writerow([row.get(key, '') for key in keys]) + for a in result_container.answers: + row = {'title': a, 'type': 'answer'} + csv.writerow([row.get(key, '') for key in keys]) + for a in result_container.suggestions: + row = {'title': a, 'type': 'suggestion'} + csv.writerow([row.get(key, '') for key in keys]) + for a in result_container.corrections: + row = {'title': a, 'type': 'correction'} csv.writerow([row.get(key, '') for key in keys]) csv.stream.seek(0) response = Response(csv.stream.read(), mimetype='application/csv') -- cgit v1.2.3 From 58a630308a95f886db9de19d562e11890ac35e07 Mon Sep 17 00:00:00 2001 From: Adam Tauber Date: Fri, 13 Mar 2020 00:57:01 +0100 Subject: [fix] convert query to string to produce valid filename for csv output --- searx/webapp.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'searx/webapp.py') diff --git a/searx/webapp.py b/searx/webapp.py index 49129d14e..0c5ed4570 100644 --- a/searx/webapp.py +++ b/searx/webapp.py @@ -643,7 +643,7 @@ def index(): csv.writerow([row.get(key, '') for key in keys]) csv.stream.seek(0) response = Response(csv.stream.read(), mimetype='application/csv') - cont_disp = 'attachment;Filename=searx_-_{0}.csv'.format(search_query.query) + cont_disp = 'attachment;Filename=searx_-_{0}.csv'.format(search_query.query.decode('utf-8')) response.headers.add('Content-Disposition', cont_disp) return response elif output_format == 'rss': -- cgit v1.2.3 From baca55c94e002abbdeb428b31ab92f558195adda Mon Sep 17 00:00:00 2001 From: Adam Tauber Date: Mon, 16 Mar 2020 00:22:15 +0100 Subject: [fix] handle weights in accept language parsing - fixes w3ms en;q=1.0 --- searx/webapp.py | 3 +++ 1 file changed, 3 insertions(+) (limited to 'searx/webapp.py') diff --git a/searx/webapp.py b/searx/webapp.py index 0c5ed4570..cfb552514 100644 --- a/searx/webapp.py +++ b/searx/webapp.py @@ -178,9 +178,12 @@ flask_babel.get_translations = _get_translations def _get_browser_language(request, lang_list): for lang in request.headers.get("Accept-Language", "en").split(","): + if ';' in lang: + lang = lang.split(';')[0] locale = match_language(lang, lang_list, fallback=None) if locale is not None: return locale + return settings['search']['default_lang'] or 'en' @babel.localeselector -- cgit v1.2.3 From 822aee94a2e50923252faf7ae11b4b03017c1a1a Mon Sep 17 00:00:00 2001 From: Adam Tauber Date: Mon, 16 Mar 2020 00:22:38 +0100 Subject: [fix] remove debug print --- searx/webapp.py | 1 - 1 file changed, 1 deletion(-) (limited to 'searx/webapp.py') diff --git a/searx/webapp.py b/searx/webapp.py index cfb552514..b3928921e 100644 --- a/searx/webapp.py +++ b/searx/webapp.py @@ -650,7 +650,6 @@ def index(): response.headers.add('Content-Disposition', cont_disp) return response elif output_format == 'rss': - print(results) response_rss = render( 'opensearch_response_rss.xml', results=results, -- cgit v1.2.3 From 04c687403e21f883f9614e6a24df9ec450cfc111 Mon Sep 17 00:00:00 2001 From: Markus Heiser Date: Wed, 25 Mar 2020 11:49:33 +0100 Subject: [fix] brands: add variables from build env to jinja templating We have some variables in the build environment which are also needed in the templating process. Theses variables are relavant if one creates a fork with its own branding. We treat these variables under the term 'brands'. Signed-off-by: Markus Heiser --- searx/webapp.py | 3 +++ 1 file changed, 3 insertions(+) mode change 100644 => 100755 searx/webapp.py (limited to 'searx/webapp.py') diff --git a/searx/webapp.py b/searx/webapp.py old mode 100644 new mode 100755 index b3928921e..c6b52d6ab --- a/searx/webapp.py +++ b/searx/webapp.py @@ -57,6 +57,7 @@ from babel.support import Translations import flask_babel from flask_babel import Babel, gettext, format_date, format_decimal from flask.json import jsonify +from searx import brand from searx import settings, searx_dir, searx_debug from searx.exceptions import SearxParameterException from searx.engines import ( @@ -427,6 +428,8 @@ def render(template_name, override_theme=None, **kwargs): kwargs['preferences'] = request.preferences + kwargs['brand'] = brand + kwargs['scripts'] = set() for plugin in request.user_plugins: for script in plugin.js_dependencies: -- cgit v1.2.3 From ace7d30aed0bdff07e97cdb3900c38633877cdcd Mon Sep 17 00:00:00 2001 From: Markus Heiser Date: Wed, 25 Mar 2020 17:12:02 +0100 Subject: webapp.py: partial code review (no functional change) Signed-off-by: Markus Heiser --- searx/webapp.py | 69 ++++++++++++++++++++++++++++++++++----------------------- 1 file changed, 41 insertions(+), 28 deletions(-) (limited to 'searx/webapp.py') diff --git a/searx/webapp.py b/searx/webapp.py index c6b52d6ab..3af5c57b4 100755 --- a/searx/webapp.py +++ b/searx/webapp.py @@ -958,34 +958,47 @@ def clear_cookies(): @app.route('/config') def config(): - return jsonify({'categories': list(categories.keys()), - 'engines': [{'name': name, - 'categories': engine.categories, - 'shortcut': engine.shortcut, - 'enabled': not engine.disabled, - 'paging': engine.paging, - 'language_support': engine.language_support, - 'supported_languages': - list(engine.supported_languages.keys()) - if isinstance(engine.supported_languages, dict) - else engine.supported_languages, - 'safesearch': engine.safesearch, - 'time_range_support': engine.time_range_support, - 'timeout': engine.timeout} - for name, engine in engines.items() if request.preferences.validate_token(engine)], - 'plugins': [{'name': plugin.name, - 'enabled': plugin.default_on} - for plugin in plugins], - 'instance_name': settings['general']['instance_name'], - 'locales': settings['locales'], - 'default_locale': settings['ui']['default_locale'], - 'autocomplete': settings['search']['autocomplete'], - 'safe_search': settings['search']['safe_search'], - 'default_theme': settings['ui']['default_theme'], - 'version': VERSION_STRING, - 'doi_resolvers': [r for r in settings['doi_resolvers']], - 'default_doi_resolver': settings['default_doi_resolver'], - }) + """Return configuration in JSON format.""" + _engines = [] + for name, engine in engines.items(): + if not request.preferences.validate_token(engine): + continue + + supported_languages = engine.supported_languages + if isinstance(engine.supported_languages, dict): + supported_languages = list(engine.supported_languages.keys()) + + _engines.append({ + 'name': name, + 'categories': engine.categories, + 'shortcut': engine.shortcut, + 'enabled': not engine.disabled, + 'paging': engine.paging, + 'language_support': engine.language_support, + 'supported_languages': supported_languages, + 'safesearch': engine.safesearch, + 'time_range_support': engine.time_range_support, + 'timeout': engine.timeout + }) + + _plugins = [] + for _ in plugins: + _plugins.append({'name': _.name, 'enabled': _.default_on}) + + return jsonify({ + 'categories': list(categories.keys()), + 'engines': _engines, + 'plugins': _plugins, + 'instance_name': settings['general']['instance_name'], + 'locales': settings['locales'], + 'default_locale': settings['ui']['default_locale'], + 'autocomplete': settings['search']['autocomplete'], + 'safe_search': settings['search']['safe_search'], + 'default_theme': settings['ui']['default_theme'], + 'version': VERSION_STRING, + 'doi_resolvers': [r for r in settings['doi_resolvers']], + 'default_doi_resolver': settings['default_doi_resolver'], + }) @app.errorhandler(404) -- cgit v1.2.3 From 4d6482823764c840415a6023d945b5699a53ba2a Mon Sep 17 00:00:00 2001 From: Markus Heiser Date: Wed, 25 Mar 2020 17:28:32 +0100 Subject: webapp.py: expose the brand variable in the /config URL. E.g. helpful for searx-stats2 Signed-off-by: Markus Heiser --- searx/webapp.py | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'searx/webapp.py') diff --git a/searx/webapp.py b/searx/webapp.py index 3af5c57b4..c910230ab 100755 --- a/searx/webapp.py +++ b/searx/webapp.py @@ -996,6 +996,10 @@ def config(): 'safe_search': settings['search']['safe_search'], 'default_theme': settings['ui']['default_theme'], 'version': VERSION_STRING, + 'brand': { + 'GIT_URL': brand.GIT_URL, + 'DOCS_URL': brand.DOCS_URL + }, 'doi_resolvers': [r for r in settings['doi_resolvers']], 'default_doi_resolver': settings['default_doi_resolver'], }) -- cgit v1.2.3 From ba7c8d7b960c3a3f288db162a51b76a2a935a605 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?No=C3=A9mi=20V=C3=A1nyi?= Date: Wed, 15 Apr 2020 23:24:12 +0200 Subject: [fix] remove usage of request context where not available --- searx/webapp.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'searx/webapp.py') diff --git a/searx/webapp.py b/searx/webapp.py index c910230ab..9d76d8441 100755 --- a/searx/webapp.py +++ b/searx/webapp.py @@ -56,6 +56,7 @@ from flask import ( from babel.support import Translations import flask_babel from flask_babel import Babel, gettext, format_date, format_decimal +from flask.ctx import has_request_context from flask.json import jsonify from searx import brand from searx import settings, searx_dir, searx_debug @@ -165,13 +166,11 @@ _flask_babel_get_translations = flask_babel.get_translations # monkey patch for flask_babel.get_translations def _get_translations(): - translation_locale = request.form.get('use-translation') - if translation_locale: + if has_request_context() and request.form.get('use-translation') == 'oc': babel_ext = flask_babel.current_app.extensions['babel'] - translation = Translations.load(next(babel_ext.translation_directories), 'oc') - else: - translation = _flask_babel_get_translations() - return translation + return Translations.load(next(babel_ext.translation_directories), 'oc') + + return _flask_babel_get_translations() flask_babel.get_translations = _get_translations -- cgit v1.2.3 From bce3830b8dd9322e4e93d0003aa86e03c03e2dca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?No=C3=A9mi=20V=C3=A1nyi?= Date: Fri, 17 Apr 2020 16:31:02 +0200 Subject: [fix] translate engine errors to Occitan when configured --- searx/webapp.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'searx/webapp.py') diff --git a/searx/webapp.py b/searx/webapp.py index 9d76d8441..8c3531069 100755 --- a/searx/webapp.py +++ b/searx/webapp.py @@ -626,7 +626,7 @@ def index(): 'corrections': list(result_container.corrections), 'infoboxes': result_container.infoboxes, 'suggestions': list(result_container.suggestions), - 'unresponsive_engines': list(result_container.unresponsive_engines)}, + 'unresponsive_engines': __get_translated_errors(result_container.unresponsive_engines)}, # noqa default=lambda item: list(item) if isinstance(item, set) else item), mimetype='application/json') elif output_format == 'csv': @@ -694,7 +694,7 @@ def index(): corrections=correction_urls, infoboxes=result_container.infoboxes, paging=result_container.paging, - unresponsive_engines=result_container.unresponsive_engines, + unresponsive_engines=__get_translated_errors(result_container.unresponsive_engines), current_language=match_language(search_query.lang, LANGUAGE_CODES, fallback=request.preferences.get_value("language")), @@ -705,6 +705,16 @@ def index(): ) +def __get_translated_errors(unresponsive_engines): + translated_errors = [] + for unresponsive_engine in unresponsive_engines: + error_msg = gettext(unresponsive_engine[1]) + if unresponsive_engine[2]: + error_msg = "{} {}".format(error_msg, unresponsive_engine[2]) + translated_errors.append((unresponsive_engine[0], error_msg)) + return translated_errors + + @app.route('/about', methods=['GET']) def about(): """Render about page""" -- cgit v1.2.3