Przeglądaj źródła

[enh] preferences added

asciimoo 11 lat temu
rodzic
commit
1df697305c
1 zmienionych plików z 29 dodań i 10 usunięć
  1. 29
    10
      searx/webapp.py

+ 29
- 10
searx/webapp.py Wyświetl plik

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'
128
-                        ,results=results
129
-                        ,q=request_data['q']
130
-                        ,selected_categories=selected_categories
131
-                        ,number_of_results=len(results)
132
-                        ,suggestions=suggestions
133
-                        )
134
-    resp = make_response(template)
135
-    resp.set_cookie('categories', ','.join(selected_categories))
127
+    return render('results.html'
128
+                 ,results=results
129
+                 ,q=request_data['q']
130
+                 ,selected_categories=selected_categories
131
+                 ,number_of_results=len(results)
132
+                 ,suggestions=suggestions
133
+                 )
136
 
134
 
137
-    return resp
138
 
135
 
139
 @app.route('/about', methods=['GET'])
136
 @app.route('/about', methods=['GET'])
140
 def about():
137
 def 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'])
145
 def stats():
162
 def 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'])
151
 def robots():
169
 def robots():
152
     return Response("""User-agent: *
170
     return Response("""User-agent: *
155
 Disallow: /stats
173
 Disallow: /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'])
159
 def opensearch():
178
 def opensearch():
160
     global opensearch_xml
179
     global opensearch_xml