1
0
mirror of https://github.com/searxng/searxng.git synced 2024-11-22 12:10:11 +01:00

[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
This commit is contained in:
Adam Tauber 2016-11-14 22:07:23 +01:00
parent 88dfee858e
commit 832cf37a97
2 changed files with 25 additions and 6 deletions

View File

@ -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 %}

View File

@ -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)