From d4d2dd9cb30df9a7d3ffcaf574b59f66d0f8917c Mon Sep 17 00:00:00 2001 From: Alexandre Flament Date: Sat, 30 May 2015 12:15:23 +0200 Subject: [PATCH 1/2] [enh] oscar theme: display engine response times in the preferences --- searx/templates/oscar/preferences.html | 45 ++++++++++++++++++++------ searx/webapp.py | 19 +++++++++++ 2 files changed, 55 insertions(+), 9 deletions(-) diff --git a/searx/templates/oscar/preferences.html b/searx/templates/oscar/preferences.html index 693167807..ee4e6ab57 100644 --- a/searx/templates/oscar/preferences.html +++ b/searx/templates/oscar/preferences.html @@ -134,21 +134,48 @@
+
+ + + {% if not rtl %} + + + + + + + {% else %} + + + + + + + {% endif %} + {% for search_engine in engines_by_category[categ] %} {% if not search_engine.private %} -
+
{% if not rtl %} -
{{ search_engine.name }} ({{ shortcuts[search_engine.name] }})
+ + + + + + + {% else %} + + + + + + {% endif %} -
- {{ checkbox_toggle('engine_' + search_engine.name|replace(' ', '_') + '__' + categ|replace(' ', '_'), (search_engine.name, categ) in blocked_engines) }} -
- {% if rtl %} -
{{ search_engine.name }} ({{ shortcuts[search_engine.name] }})‎
- {% endif %} - + {% endif %} {% endfor %} +
{{ _("Allow") }}{{ _("Engine name") }}{{ _("Shortcut") }}{{ _("SafeSearch") }}{{ _("Avg. time") }}{{ _("Max time") }}{{ _("Max time") }}{{ _("Avg. time") }}{{ _("SafeSearch") }}{{ _("Shortcut") }}{{ _("Engine name") }}{{ _("Allow") }}
{{ checkbox_toggle('engine_' + search_engine.name|replace(' ', '_') + '__' + categ|replace(' ', '_'), (search_engine.name, categ) in blocked_engines) }}{{ search_engine.name }}{{ shortcuts[search_engine.name] }}{{ 'N/A' if stats[search_engine.name].time==None else stats[search_engine.name].time }}{{ search_engine.timeout }}{{ search_engine.timeout }}{{ 'N/A' if stats[search_engine.name].time==None else stats[search_engine.name].time }}{{ shortcuts[search_engine.name] }}{{ search_engine.name }}{{ checkbox_toggle('engine_' + search_engine.name|replace(' ', '_') + '__' + categ|replace(' ', '_'), (search_engine.name, categ) in blocked_engines) }}
+
diff --git a/searx/webapp.py b/searx/webapp.py index 3ef5a72c8..8587d546a 100644 --- a/searx/webapp.py +++ b/searx/webapp.py @@ -623,6 +623,24 @@ def preferences(): resp.set_cookie('theme', theme, max_age=cookie_max_age) return resp + + # stats for preferences page + stats = {} + + for c in categories: + for e in categories[c]: + stats[e.name] = {'time': None, + 'warn_timeout': False, + 'warn_time': False} + if e.timeout > settings['server']['request_timeout']: + stats[e.name]['warn_timeout'] = True + + for engine_stat in get_engines_stats()[0][1]: + stats[engine_stat.get('name')]['time'] = round(engine_stat.get('avg'), 3) + if engine_stat.get('avg') > settings['server']['request_timeout']: + stats[engine_stat.get('name')]['warn_time'] = True + # end of stats + return render('preferences.html', locales=settings['locales'], current_locale=get_locale(), @@ -630,6 +648,7 @@ def preferences(): image_proxy=image_proxy, language_codes=language_codes, engines_by_category=categories, + stats=stats, blocked_engines=blocked_engines, autocomplete_backends=autocomplete_backends, shortcuts={y: x for x, y in engine_shortcuts.items()}, From 6765823c56ed74d56ce402f7df6fe63cca7fe8fe Mon Sep 17 00:00:00 2001 From: Alexandre Flament Date: Sat, 30 May 2015 12:37:18 +0200 Subject: [PATCH 2/2] [fix] set engine.safesearch to False if not defined --- searx/engines/__init__.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/searx/engines/__init__.py b/searx/engines/__init__.py index 18a45d851..42e1f08bc 100644 --- a/searx/engines/__init__.py +++ b/searx/engines/__init__.py @@ -71,6 +71,9 @@ def load_engine(engine_data): if not hasattr(engine, 'language_support'): engine.language_support = True + if not hasattr(engine, 'safesearch'): + engine.safesearch = False + if not hasattr(engine, 'timeout'): engine.timeout = settings['server']['request_timeout']