[enh] engine customisation init

This commit is contained in:
asciimoo 2014-02-07 00:35:15 +01:00
parent b8d836e445
commit c0013edcdd
5 changed files with 63 additions and 49 deletions

View File

@ -49,7 +49,7 @@ input[type="submit"] { padding: 2px 6px; margin: 2px 4px; display: inline-block;
input[type="checkbox"] { visibility: hidden; } input[type="checkbox"] { visibility: hidden; }
fieldset { margin: 8px; } fieldset { margin: 8px; border: 1px solid #3498DB; }
#categories { margin: 0 10px; } #categories { margin: 0 10px; }
@ -57,7 +57,7 @@ fieldset { margin: 8px; }
.checkbox_container input { .checkbox_container input {
display: none; display: none;
} }
.checkbox_container label { .checkbox_container label, .engine_checkbox label {
cursor: pointer; cursor: pointer;
padding: 4px 10px; padding: 4px 10px;
margin: 0; margin: 0;
@ -77,6 +77,12 @@ fieldset { margin: 8px; }
.search .checkbox_container label:hover { border-bottom: 4px solid #3498DB; } .search .checkbox_container label:hover { border-bottom: 4px solid #3498DB; }
.search .checkbox_container input[type="checkbox"]:checked + label { border-bottom: 4px solid #2980B9; } .search .checkbox_container input[type="checkbox"]:checked + label { border-bottom: 4px solid #2980B9; }
.engine_checkbox { padding: 4px; }
label.allow { background: #E74C3C; color: #FFFFFF; padding: 4px 8px; display: none; }
label.deny { background: #2ECC71; padding: 4px 8px; display: inline; }
.engine_checkbox input[type="checkbox"]:checked + label:nth-child(2) + label { display: none; }
.engine_checkbox input[type="checkbox"]:checked + label.allow { display: inline; }
a { text-decoration: none; color: #1a11be; } a { text-decoration: none; color: #1a11be; }
a:visited { color: #7b11be; } a:visited { color: #7b11be; }
@ -116,8 +122,9 @@ a:visited { color: #7b11be; }
.percentage { position: relative; width: 300px; } .percentage { position: relative; width: 300px; }
.percentage div { background: #444444; } .percentage div { background: #444444; }
td { padding: 0 4px; } table { width: 100%; }
tr:hover td { background: #DDDDDD; } td { padding: 0 4px; }
tr:hover { background: #DDDDDD; }
#search_wrapper { position: relative; max-width: 600px; padding: 10px; } #search_wrapper { position: relative; max-width: 600px; padding: 10px; }
.center #search_wrapper { margin-left: auto; margin-right: auto; } .center #search_wrapper { margin-left: auto; margin-right: auto; }

View File

@ -1,27 +0,0 @@
{% extends 'base.html' %}
{% block content %}
<div class="row">
<h2>{{ _('Currently used search engines') }}</h2>
<table style="width: 80%;">
<tr>
<th>{{ _('Engine name') }}</th>
<th>{{ _('Shortcut') }}</th>
<th>{{ _('Category') }}</th>
</tr>
{% for (categ,search_engines) in categs %}
{% for search_engine in search_engines %}
{% if not search_engine.private %}
<tr>
<td>{{ search_engine.name }}</td>
<td>{{ shortcuts[search_engine.name] }}</td>
<td>{{ _(categ) }}</td>
</tr>
{% endif %}
{% endfor %}
{% endfor %}
</table>
<p class="right"><a href="/">{{ _('back') }}</a></p>
</div>
{% endblock %}

View File

@ -32,6 +32,35 @@
</select> </select>
</p> </p>
</fieldset> </fieldset>
<fieldset>
<legend>{{ _('Currently used search engines') }}</legend>
<table>
<tr>
<th>{{ _('Engine name') }}</th>
<th>{{ _('Shortcut') }}</th>
<th>{{ _('Category') }}</th>
<th>{{ _('Allow') }} / {{ _('Deny') }}</th>
</tr>
{% for (categ,search_engines) in categs %}
{% for search_engine in search_engines %}
{% if not search_engine.private %}
<tr>
<td>{{ search_engine.name }}</td>
<td>{{ shortcuts[search_engine.name] }}</td>
<td>{{ _(categ) }}</td>
<td class="engine_checkbox">
<input type="checkbox" id="engine_{{ categ}}_{{ search_engine.name|replace(' ', '_') }}" name="engine_{{ search_engine.name }}"{% if search_engine.name in blocked_engines %} checked="checked"{% endif %} />
<label class="allow" for="engine_{{ categ }}_{{ search_engine.name|replace(' ', '_') }}">{{ _('Allow') }}</label>
<label class="deny" for="engine_{{ categ }}_{{ search_engine.name|replace(' ', '_') }}">{{ _('Deny') }}</label>
</td>
</tr>
{% endif %}
{% endfor %}
{% endfor %}
</table>
</fieldset>
<p class="small_font">{{ _('These settings are stored in your cookies, this allows us not to store this data about you.') }} <p class="small_font">{{ _('These settings are stored in your cookies, this allows us not to store this data about you.') }}
<br /> <br />
{{ _("These cookies serve your sole convenience, we don't use these cookies to track you.") }} {{ _("These cookies serve your sole convenience, we don't use these cookies to track you.") }}

View File

@ -124,11 +124,6 @@ class ViewsTestCase(SearxTestCase):
self.assertEqual(result.status_code, 200) self.assertEqual(result.status_code, 200)
self.assertIn('<h1>About <a href="/">searx</a></h1>', result.data) self.assertIn('<h1>About <a href="/">searx</a></h1>', result.data)
def test_engines(self):
result = self.app.get('/engines')
self.assertEqual(result.status_code, 200)
self.assertIn('<h2>Currently used search engines</h2>', result.data)
def test_preferences(self): def test_preferences(self):
result = self.app.get('/preferences') result = self.app.get('/preferences')
self.assertEqual(result.status_code, 200) self.assertEqual(result.status_code, 200)

View File

@ -242,17 +242,6 @@ def about():
return render('about.html') return render('about.html')
@app.route('/engines', methods=['GET'])
def list_engines():
"""Render engines page.
List of all supported engines.
"""
return render('engines.html',
categs=categories.items(),
shortcuts={y: x for x, y in engine_shortcuts.items()})
@app.route('/preferences', methods=['GET', 'POST']) @app.route('/preferences', methods=['GET', 'POST'])
def preferences(): def preferences():
"""Render preferences page. """Render preferences page.
@ -264,7 +253,11 @@ def preferences():
and request.cookies['language'] in (x[0] for x in language_codes): and request.cookies['language'] in (x[0] for x in language_codes):
lang = request.cookies['language'] lang = request.cookies['language']
if request.method == 'POST': blocked_engines = []
if request.method == 'GET':
blocked_engines = request.cookies.get('blocked_engines', '').split(',')
else:
selected_categories = [] selected_categories = []
locale = None locale = None
for pd_name, pd in request.form.items(): for pd_name, pd in request.form.items():
@ -278,10 +271,24 @@ def preferences():
elif pd_name == 'language' and (pd == 'all' or elif pd_name == 'language' and (pd == 'all' or
pd in (x[0] for pd in (x[0] for
x in language_codes)): x in language_codes)):
locale = pd
lang = pd lang = pd
elif pd_name.startswith('engine_'):
engine_name = pd_name.replace('engine_', '', 1)
if engine_name in engines:
blocked_engines.append(engine_name)
resp = make_response(redirect('/')) resp = make_response(redirect('/'))
user_blocked_engines = request.cookies.get('blocked_engines', '').split(',') # noqa
if sorted(blocked_engines) != sorted(user_blocked_engines):
# cookie max age: 4 weeks
resp.set_cookie(
'blocked_engines', ','.join(blocked_engines),
max_age=60 * 60 * 24 * 7 * 4
)
if locale: if locale:
# cookie max age: 4 weeks # cookie max age: 4 weeks
resp.set_cookie( resp.set_cookie(
@ -307,7 +314,10 @@ def preferences():
locales=settings['locales'], locales=settings['locales'],
current_locale=get_locale(), current_locale=get_locale(),
current_language=lang or 'all', current_language=lang or 'all',
language_codes=language_codes) language_codes=language_codes,
categs=categories.items(),
blocked_engines=blocked_engines,
shortcuts={y: x for x, y in engine_shortcuts.items()})
@app.route('/stats', methods=['GET']) @app.route('/stats', methods=['GET'])