Browse Source

add optional request with GET method for search and results pages

Matej Cotman 11 years ago
parent
commit
32e98967b7

+ 9
- 0
searx/templates/preferences.html View File

44
         </p>
44
         </p>
45
     </fieldset>
45
     </fieldset>
46
     <fieldset>
46
     <fieldset>
47
+        <legend>{{ _('Method') }}</legend>
48
+        <p>
49
+        <select name='method'>
50
+            <option value="POST" {% if method == 'POST' %}selected="selected"{% endif %}>POST</option>
51
+            <option value="GET" {% if method == 'GET' %}selected="selected"{% endif %}>GET</option>
52
+        </select>
53
+        </p>
54
+    </fieldset>
55
+    <fieldset>
47
     <legend>{{ _('Currently used search engines') }}</legend>
56
     <legend>{{ _('Currently used search engines') }}</legend>
48
 
57
 
49
     <table>
58
     <table>

+ 4
- 4
searx/templates/results.html View File

10
         {% if suggestions %}
10
         {% if suggestions %}
11
         <div id="suggestions"><span>{{ _('Suggestions') }}</span>
11
         <div id="suggestions"><span>{{ _('Suggestions') }}</span>
12
             {% for suggestion in suggestions %}
12
             {% for suggestion in suggestions %}
13
-            <form method="post" action="{{ url_for('index') }}">
13
+            <form method="{{ method or 'POST' }}" action="{{ url_for('index') }}">
14
                 <input type="hidden" name="q" value="{{ suggestion }}">
14
                 <input type="hidden" name="q" value="{{ suggestion }}">
15
                 <input type="submit" value="{{ suggestion }}" />
15
                 <input type="submit" value="{{ suggestion }}" />
16
             </form>
16
             </form>
25
         <div id="apis">
25
         <div id="apis">
26
         {{ _('Download results') }}
26
         {{ _('Download results') }}
27
         {% for output_type in ('csv', 'json', 'rss') %}
27
         {% for output_type in ('csv', 'json', 'rss') %}
28
-        <form method="post" action="{{ url_for('index') }}">
28
+        <form method="{{ method or 'POST' }}" action="{{ url_for('index') }}">
29
             <div class="left">
29
             <div class="left">
30
             <input type="hidden" name="q" value="{{ q }}" />
30
             <input type="hidden" name="q" value="{{ q }}" />
31
             <input type="hidden" name="format" value="{{ output_type }}" />
31
             <input type="hidden" name="format" value="{{ output_type }}" />
52
     {% if paging %}
52
     {% if paging %}
53
     <div id="pagination">
53
     <div id="pagination">
54
         {% if pageno > 1 %}
54
         {% if pageno > 1 %}
55
-            <form method="post" action="{{ url_for('index') }}">
55
+            <form method="{{ method or 'POST' }}" action="{{ url_for('index') }}">
56
                 <div class="left">
56
                 <div class="left">
57
                 <input type="hidden" name="q" value="{{ q }}" />
57
                 <input type="hidden" name="q" value="{{ q }}" />
58
                 {% for category in selected_categories %}
58
                 {% for category in selected_categories %}
63
                 </div>
63
                 </div>
64
             </form>
64
             </form>
65
         {% endif %}
65
         {% endif %}
66
-        <form method="post" action="{{ url_for('index') }}">
66
+        <form method="{{ method or 'POST' }}" action="{{ url_for('index') }}">
67
             <div class="left">
67
             <div class="left">
68
             {% for category in selected_categories %}
68
             {% for category in selected_categories %}
69
             <input type="hidden" name="category_{{ category }}" value="1"/>
69
             <input type="hidden" name="category_{{ category }}" value="1"/>

+ 1
- 1
searx/templates/search.html View File

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

+ 7
- 0
searx/webapp.py View File

123
     if not 'autocomplete' in kwargs:
123
     if not 'autocomplete' in kwargs:
124
         kwargs['autocomplete'] = autocomplete
124
         kwargs['autocomplete'] = autocomplete
125
 
125
 
126
+    kwargs['method'] = request.cookies.get('method', 'POST')
127
+
126
     return render_template(template_name, **kwargs)
128
     return render_template(template_name, **kwargs)
127
 
129
 
128
 
130
 
295
         selected_categories = []
297
         selected_categories = []
296
         locale = None
298
         locale = None
297
         autocomplete = ''
299
         autocomplete = ''
300
+        method = 'POST'
298
         for pd_name, pd in request.form.items():
301
         for pd_name, pd in request.form.items():
299
             if pd_name.startswith('category_'):
302
             if pd_name.startswith('category_'):
300
                 category = pd_name[9:]
303
                 category = pd_name[9:]
309
                                             pd in (x[0] for
312
                                             pd in (x[0] for
310
                                                    x in language_codes)):
313
                                                    x in language_codes)):
311
                 lang = pd
314
                 lang = pd
315
+            elif pd_name == 'method':
316
+                method = pd
312
             elif pd_name.startswith('engine_'):
317
             elif pd_name.startswith('engine_'):
313
                 engine_name = pd_name.replace('engine_', '', 1)
318
                 engine_name = pd_name.replace('engine_', '', 1)
314
                 if engine_name in engines:
319
                 if engine_name in engines:
348
                 max_age=cookie_max_age
353
                 max_age=cookie_max_age
349
             )
354
             )
350
 
355
 
356
+        resp.set_cookie('method', method, max_age=cookie_max_age)
357
+
351
         return resp
358
         return resp
352
     return render('preferences.html',
359
     return render('preferences.html',
353
                   locales=settings['locales'],
360
                   locales=settings['locales'],