Merge pull request #61 from matejc/optional_search_get

Optional search get
This commit is contained in:
Adam Tauber 2014-04-08 17:51:30 +02:00
commit 44d3af9fb2
5 changed files with 30 additions and 6 deletions

View File

@ -43,6 +43,15 @@
</select> </select>
</p> </p>
</fieldset> </fieldset>
<fieldset>
<legend>{{ _('Method') }}</legend>
<p>
<select name='method'>
<option value="POST" {% if method == 'POST' %}selected="selected"{% endif %}>POST</option>
<option value="GET" {% if method == 'GET' %}selected="selected"{% endif %}>GET</option>
</select>
</p>
</fieldset>
<fieldset> <fieldset>
<legend>{{ _('Currently used search engines') }}</legend> <legend>{{ _('Currently used search engines') }}</legend>

View File

@ -10,7 +10,7 @@
{% if suggestions %} {% if suggestions %}
<div id="suggestions"><span>{{ _('Suggestions') }}</span> <div id="suggestions"><span>{{ _('Suggestions') }}</span>
{% for suggestion in suggestions %} {% for suggestion in suggestions %}
<form method="post" action="{{ url_for('index') }}"> <form method="{{ method or 'POST' }}" action="{{ url_for('index') }}">
<input type="hidden" name="q" value="{{ suggestion }}"> <input type="hidden" name="q" value="{{ suggestion }}">
<input type="submit" value="{{ suggestion }}" /> <input type="submit" value="{{ suggestion }}" />
</form> </form>
@ -25,7 +25,7 @@
<div id="apis"> <div id="apis">
{{ _('Download results') }} {{ _('Download results') }}
{% for output_type in ('csv', 'json', 'rss') %} {% for output_type in ('csv', 'json', 'rss') %}
<form method="post" action="{{ url_for('index') }}"> <form method="{{ method or 'POST' }}" action="{{ url_for('index') }}">
<div class="left"> <div class="left">
<input type="hidden" name="q" value="{{ q }}" /> <input type="hidden" name="q" value="{{ q }}" />
<input type="hidden" name="format" value="{{ output_type }}" /> <input type="hidden" name="format" value="{{ output_type }}" />
@ -52,7 +52,7 @@
{% if paging %} {% if paging %}
<div id="pagination"> <div id="pagination">
{% if pageno > 1 %} {% if pageno > 1 %}
<form method="post" action="{{ url_for('index') }}"> <form method="{{ method or 'POST' }}" action="{{ url_for('index') }}">
<div class="left"> <div class="left">
<input type="hidden" name="q" value="{{ q }}" /> <input type="hidden" name="q" value="{{ q }}" />
{% for category in selected_categories %} {% for category in selected_categories %}
@ -63,7 +63,7 @@
</div> </div>
</form> </form>
{% endif %} {% endif %}
<form method="post" action="{{ url_for('index') }}"> <form method="{{ method or 'POST' }}" action="{{ url_for('index') }}">
<div class="left"> <div class="left">
{% for category in selected_categories %} {% for category in selected_categories %}
<input type="hidden" name="category_{{ category }}" value="1"/> <input type="hidden" name="category_{{ category }}" value="1"/>

View File

@ -1,4 +1,4 @@
<form method="post" action="{{ url_for('index') }}" id="search_form"> <form method="{{ method or 'POST' }}" action="{{ url_for('index') }}" id="search_form">
<div id="search_wrapper"> <div id="search_wrapper">
<input type="text" placeholder="{{ _('Search for...') }}" id="q" class="q" name="q" tabindex="1" autocomplete="off" {% if q %}value="{{ q }}"{% endif %}/> <input type="text" placeholder="{{ _('Search for...') }}" id="q" class="q" name="q" tabindex="1" autocomplete="off" {% if q %}value="{{ q }}"{% endif %}/>
<input type="submit" value="search" id="search_submit" /> <input type="submit" value="search" id="search_submit" />

View File

@ -123,6 +123,8 @@ def render(template_name, **kwargs):
if not 'autocomplete' in kwargs: if not 'autocomplete' in kwargs:
kwargs['autocomplete'] = autocomplete kwargs['autocomplete'] = autocomplete
kwargs['method'] = request.cookies.get('method', 'POST')
return render_template(template_name, **kwargs) return render_template(template_name, **kwargs)
@ -291,6 +293,7 @@ def preferences():
selected_categories = [] selected_categories = []
locale = None locale = None
autocomplete = '' autocomplete = ''
method = 'POST'
for pd_name, pd in request.form.items(): for pd_name, pd in request.form.items():
if pd_name.startswith('category_'): if pd_name.startswith('category_'):
category = pd_name[9:] category = pd_name[9:]
@ -305,6 +308,8 @@ def preferences():
pd in (x[0] for pd in (x[0] for
x in language_codes)): x in language_codes)):
lang = pd lang = pd
elif pd_name == 'method':
method = pd
elif pd_name.startswith('engine_'): elif pd_name.startswith('engine_'):
engine_name = pd_name.replace('engine_', '', 1) engine_name = pd_name.replace('engine_', '', 1)
if engine_name in engines: if engine_name in engines:
@ -344,6 +349,8 @@ def preferences():
max_age=cookie_max_age max_age=cookie_max_age
) )
resp.set_cookie('method', method, max_age=cookie_max_age)
return resp return resp
return render('preferences.html', return render('preferences.html',
locales=settings['locales'], locales=settings['locales'],

View File

@ -1,4 +1,5 @@
[versions] [versions]
Babel = 1.3
Flask = 0.10.1 Flask = 0.10.1
Flask-Babel = 0.9 Flask-Babel = 0.9
Jinja2 = 2.7.2 Jinja2 = 2.7.2
@ -14,9 +15,11 @@ docutils = 0.11
flake8 = 2.1.0 flake8 = 2.1.0
itsdangerous = 0.23 itsdangerous = 0.23
mccabe = 0.2.1 mccabe = 0.2.1
mock = 1.0.1
pep8 = 1.4.6 pep8 = 1.4.6
plone.testing = 4.0.8 plone.testing = 4.0.8
pyflakes = 0.7.3 pyflakes = 0.7.3
pytz = 2013b
pyyaml = 3.10 pyyaml = 3.10
requests = 2.2.0 requests = 2.2.0
robotframework-debuglibrary = 0.3 robotframework-debuglibrary = 0.3
@ -24,6 +27,7 @@ robotframework-httplibrary = 0.4.2
robotframework-selenium2library = 1.5.0 robotframework-selenium2library = 1.5.0
robotsuite = 1.4.2 robotsuite = 1.4.2
selenium = 2.39.0 selenium = 2.39.0
speaklater = 1.3
unittest2 = 0.5.1 unittest2 = 0.5.1
waitress = 0.8.8 waitress = 0.8.8
zc.recipe.testrunner = 2.0.0 zc.recipe.testrunner = 2.0.0
@ -72,7 +76,7 @@ setuptools = 2.1
# Required by: # Required by:
# zope.testrunner==4.4.1 # zope.testrunner==4.4.1
six = 1.5.2 six = 1.6.1
# Required by: # Required by:
# collective.recipe.omelette==0.16 # collective.recipe.omelette==0.16
@ -93,3 +97,7 @@ zope.testing = 4.1.2
# Required by: # Required by:
# zc.recipe.testrunner==2.0.0 # zc.recipe.testrunner==2.0.0
zope.testrunner = 4.4.1 zope.testrunner = 4.4.1
# Required by:
# searx==0.3.0
python-dateutil = 2.2