logo

searx

My custom branche(s) on searx, a meta-search engine
commit: 832cf37a97b97061a26e2fdf49c293d26e917ef5
parent: 88dfee858e93e54ad6e54801f88b93bfdc2bb149
Author: Adam Tauber <asciimoo@gmail.com>
Date:   Mon, 14 Nov 2016 22:07:23 +0100

[enh] display errors

also tried flask's flash feature but flask creates session cookies if it
isn't flushed. Avoiding session cookies to preserve privacy

Diffstat:

Msearx/templates/oscar/base.html15+++++++++++++++
Msearx/webapp.py16++++++++++------
2 files changed, 25 insertions(+), 6 deletions(-)

diff --git a/searx/templates/oscar/base.html b/searx/templates/oscar/base.html @@ -1,3 +1,4 @@ +{% from 'oscar/macros.html' import icon %} <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"{% if rtl %} dir="rtl"{% endif %}> <head> @@ -54,6 +55,20 @@ <body> {% include 'oscar/navbar.html' %} <div class="container"> + {% if errors %} + <div class="alert alert-danger fade in" role="alert"> + <button class="close" data-dismiss="alert" type="button"> + <span aria-hidden="true">×</span> + <span class="sr-only">{{ _('Close') }}</span> + </button> + <strong class="lead">{{ icon('info-sign') }} {{ _('Error!') }}</strong> + <ul> + {% for message in errors %} + <li>{{ message }}</li> + {% endfor %} + </ul> + </div> + {% endif %} {% block site_alert_error %} {% endblock %} diff --git a/searx/webapp.py b/searx/webapp.py @@ -344,6 +344,8 @@ def render(template_name, override_theme=None, **kwargs): kwargs['cookies'] = request.cookies + kwargs['errors'] = request.errors + kwargs['instance_name'] = settings['general']['instance_name'] kwargs['results_on_new_tab'] = request.preferences.get_value('results_on_new_tab') @@ -364,15 +366,16 @@ def render(template_name, override_theme=None, **kwargs): @app.before_request def pre_request(): - # merge GET, POST vars + request.errors = [] + preferences = Preferences(themes, categories.keys(), engines, plugins) try: preferences.parse_cookies(request.cookies) except: - # TODO throw error message to the user - logger.warning('Invalid config') + request.errors.append(gettext('Invalid settings, please edit your preferences')) request.preferences = preferences + # merge GET, POST vars # request.form request.form = dict(request.form.items()) for k, v in request.args.items(): @@ -397,7 +400,7 @@ def index(): Supported outputs: html, json, csv, rss. """ - if not request.args and not request.form: + if request.form.get('q') is None: return render( 'index.html', ) @@ -410,7 +413,8 @@ def index(): # search = Search(search_query) # without plugins search = SearchWithPlugins(search_query, request) result_container = search.search() - except Exception: + except: + request.errors.append(gettext('search error')) logger.exception('search error') return render( 'index.html', @@ -573,7 +577,7 @@ def preferences(): try: request.preferences.parse_form(request.form) except ValidationException: - # TODO use flash feature of flask + request.errors.append(gettext('Invalid settings, please edit your preferences')) return resp return request.preferences.save(resp)