|
@@ -344,6 +344,8 @@ def render(template_name, override_theme=None, **kwargs):
|
344
|
344
|
|
345
|
345
|
kwargs['cookies'] = request.cookies
|
346
|
346
|
|
|
347
|
+ kwargs['errors'] = request.errors
|
|
348
|
+
|
347
|
349
|
kwargs['instance_name'] = settings['general']['instance_name']
|
348
|
350
|
|
349
|
351
|
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):
|
364
|
366
|
|
365
|
367
|
@app.before_request
|
366
|
368
|
def pre_request():
|
367
|
|
- # merge GET, POST vars
|
|
369
|
+ request.errors = []
|
|
370
|
+
|
368
|
371
|
preferences = Preferences(themes, categories.keys(), engines, plugins)
|
369
|
372
|
try:
|
370
|
373
|
preferences.parse_cookies(request.cookies)
|
371
|
374
|
except:
|
372
|
|
- # TODO throw error message to the user
|
373
|
|
- logger.warning('Invalid config')
|
|
375
|
+ request.errors.append(gettext('Invalid settings, please edit your preferences'))
|
374
|
376
|
request.preferences = preferences
|
375
|
377
|
|
|
378
|
+ # merge GET, POST vars
|
376
|
379
|
# request.form
|
377
|
380
|
request.form = dict(request.form.items())
|
378
|
381
|
for k, v in request.args.items():
|
|
@@ -397,7 +400,7 @@ def index():
|
397
|
400
|
Supported outputs: html, json, csv, rss.
|
398
|
401
|
"""
|
399
|
402
|
|
400
|
|
- if not request.args and not request.form:
|
|
403
|
+ if request.form.get('q') is None:
|
401
|
404
|
return render(
|
402
|
405
|
'index.html',
|
403
|
406
|
)
|
|
@@ -410,7 +413,8 @@ def index():
|
410
|
413
|
# search = Search(search_query) # without plugins
|
411
|
414
|
search = SearchWithPlugins(search_query, request)
|
412
|
415
|
result_container = search.search()
|
413
|
|
- except Exception:
|
|
416
|
+ except:
|
|
417
|
+ request.errors.append(gettext('search error'))
|
414
|
418
|
logger.exception('search error')
|
415
|
419
|
return render(
|
416
|
420
|
'index.html',
|
|
@@ -573,7 +577,7 @@ def preferences():
|
573
|
577
|
try:
|
574
|
578
|
request.preferences.parse_form(request.form)
|
575
|
579
|
except ValidationException:
|
576
|
|
- # TODO use flash feature of flask
|
|
580
|
+ request.errors.append(gettext('Invalid settings, please edit your preferences'))
|
577
|
581
|
return resp
|
578
|
582
|
return request.preferences.save(resp)
|
579
|
583
|
|