logo

searx

My custom branche(s) on searx, a meta-search engine
commit: 5adb289a1c7611ade59d467b0af02763ccdcae6c
parent: e19eeeefa0358d4f39b6708ac4bdb036f2c4e733
Author: Adam Tauber <asciimoo@gmail.com>
Date:   Sat, 30 May 2015 13:32:59 +0200

Merge remote-tracking branch 'origin/ui'

Diffstat:

Msearx/engines/__init__.py3+++
Msearx/templates/oscar/preferences.html45++++++++++++++++++++++++++++++++++++---------
Msearx/webapp.py19+++++++++++++++++++
3 files changed, 58 insertions(+), 9 deletions(-)

diff --git 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'] diff --git a/searx/templates/oscar/preferences.html b/searx/templates/oscar/preferences.html @@ -134,21 +134,48 @@ <div class="tab-pane{% if loop.first %} active{% endif %} active_if_nojs" id="tab_engine_{{ categ|replace(' ', '_') }}"> <div class="container-fluid"> <fieldset> + <div class="table-responsive"> + <table class="table table-hover table-condensed table-striped"> + <tr> + {% if not rtl %} + <th>{{ _("Allow") }}</th> + <th>{{ _("Engine name") }}</th> + <th>{{ _("Shortcut") }}</th> + <th>{{ _("SafeSearch") }}</th> + <th>{{ _("Avg. time") }}</th> + <th>{{ _("Max time") }}</th> + {% else %} + <th>{{ _("Max time") }}</th> + <th>{{ _("Avg. time") }}</th> + <th>{{ _("SafeSearch") }}</th> + <th>{{ _("Shortcut") }}</th> + <th>{{ _("Engine name") }}</th> + <th>{{ _("Allow") }}</th> + {% endif %} + </tr> {% for search_engine in engines_by_category[categ] %} {% if not search_engine.private %} - <div class="row"> + <tr> {% if not rtl %} - <div class="col-xs-6 col-sm-4 col-md-4">{{ search_engine.name }} ({{ shortcuts[search_engine.name] }})</div> + <td>{{ checkbox_toggle('engine_' + search_engine.name|replace(' ', '_') + '__' + categ|replace(' ', '_'), (search_engine.name, categ) in blocked_engines) }}</td> + <th>{{ search_engine.name }}</th> + <td>{{ shortcuts[search_engine.name] }}</td> + <td><input type="checkbox" {{ "checked" if search_engine.safesearch==True else ""}} readonly="readonly" disabled="disabled"></td> + <td class="{{ 'danger' if stats[search_engine.name]['warn_time'] else '' }}">{{ 'N/A' if stats[search_engine.name].time==None else stats[search_engine.name].time }}</td> + <td class="{{ 'danger' if stats[search_engine.name]['warn_timeout'] else '' }}">{{ search_engine.timeout }}</td> + {% else %} + <td class="{{ 'danger' if stats[search_engine.name]['warn_timeout'] else '' }}">{{ search_engine.timeout }}</td> + <td class="{{ 'danger' if stats[search_engine.name]['warn_time'] else '' }}">{{ 'N/A' if stats[search_engine.name].time==None else stats[search_engine.name].time }}</td> + <td><input type="checkbox" {{ "checked" if search_engine.safesearch==True else ""}} readonly="readonly" disabled="disabled"></td> + <td>{{ shortcuts[search_engine.name] }}</td> + <th>{{ search_engine.name }}</th> + <td>{{ checkbox_toggle('engine_' + search_engine.name|replace(' ', '_') + '__' + categ|replace(' ', '_'), (search_engine.name, categ) in blocked_engines) }}</td> {% endif %} - <div class="col-xs-6 col-sm-4 col-md-4"> - {{ checkbox_toggle('engine_' + search_engine.name|replace(' ', '_') + '__' + categ|replace(' ', '_'), (search_engine.name, categ) in blocked_engines) }} - </div> - {% if rtl %} - <div class="col-xs-6 col-sm-4 col-md-4">{{ search_engine.name }} ({{ shortcuts[search_engine.name] }})&lrm;</div> - {% endif %} - </div> + </tr> {% endif %} {% endfor %} + </table> + </div> </fieldset> </div> </div> diff --git 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()},