on master help sign in
[enh] preferences added
1df6973asciimoo
searx/webapp.py+29−10
@@ -124,29 +124,47 @@ def index():
124 response.headers.add('Content-Disposition', 'attachment;Filename=searx_-_{0}.csv'.format('_'.join(query.split())))
124 response.headers.add('Content-Disposition', 'attachment;Filename=searx_-_{0}.csv'.format('_'.join(query.split())))
125 return response
125 return response
126
126
127− template = render('results.html'
127+ return render('results.html'
128− ,results=results
128+ ,results=results
129− ,q=request_data['q']
129+ ,q=request_data['q']
130− ,selected_categories=selected_categories
130+ ,selected_categories=selected_categories
131− ,number_of_results=len(results)
131+ ,number_of_results=len(results)
132− ,suggestions=suggestions
132+ ,suggestions=suggestions
133− )
133+ )
134− resp = make_response(template)
135− resp.set_cookie('categories', ','.join(selected_categories))
136
134
137− return resp
138
135
139@app.route('/about', methods=['GET'])
136@app.route('/about', methods=['GET'])
140def about():
137def about():
141 global categories
138 global categories
142 return render('about.html', categs=categories.items())
139 return render('about.html', categs=categories.items())
143
140
141+
142+@app.route('/preferences', methods=['GET', 'POST'])
143+def preferences():
144+
145+ if request.method=='POST':
146+ selected_categories = []
147+ for pd_name,pd in request.form.items():
148+ if pd_name.startswith('category_'):
149+ category = pd_name[9:]
150+ if not category in categories:
151+ continue
152+ selected_categories.append(category)
153+ if selected_categories:
154+ template = render('preferences.html', selected_categories=selected_categories)
155+ resp = make_response(template)
156+ resp.set_cookie('categories', ','.join(selected_categories))
157+ return resp
158+ return render('preferences.html')
159+
160+
144@app.route('/stats', methods=['GET'])
161@app.route('/stats', methods=['GET'])
145def stats():
162def stats():
146 global categories
163 global categories
147 stats = get_engines_stats()
164 stats = get_engines_stats()
148 return render('stats.html', stats=stats)
165 return render('stats.html', stats=stats)
149
166
167+
150@app.route('/robots.txt', methods=['GET'])
168@app.route('/robots.txt', methods=['GET'])
151def robots():
169def robots():
152 return Response("""User-agent: *
170 return Response("""User-agent: *
@@ -155,6 +173,7 @@ Allow: /about
155Disallow: /stats
173Disallow: /stats
156""", mimetype='text/plain')
174""", mimetype='text/plain')
157
175
176+
158@app.route('/opensearch.xml', methods=['GET'])
177@app.route('/opensearch.xml', methods=['GET'])
159def opensearch():
178def opensearch():
160 global opensearch_xml
179 global opensearch_xml