Browse Source

[enh] preferences added

asciimoo 11 years ago
parent
commit
1df697305c
1 changed files with 29 additions and 10 deletions
  1. 29
    10
      searx/webapp.py

+ 29
- 10
searx/webapp.py View File

@@ -124,29 +124,47 @@ def index():
124 124
         response.headers.add('Content-Disposition', 'attachment;Filename=searx_-_{0}.csv'.format('_'.join(query.split())))
125 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 136
 @app.route('/about', methods=['GET'])
140 137
 def about():
141 138
     global categories
142 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 161
 @app.route('/stats', methods=['GET'])
145 162
 def stats():
146 163
     global categories
147 164
     stats = get_engines_stats()
148 165
     return render('stats.html', stats=stats)
149 166
 
167
+
150 168
 @app.route('/robots.txt', methods=['GET'])
151 169
 def robots():
152 170
     return Response("""User-agent: *
@@ -155,6 +173,7 @@ Allow: /about
155 173
 Disallow: /stats
156 174
 """, mimetype='text/plain')
157 175
 
176
+
158 177
 @app.route('/opensearch.xml', methods=['GET'])
159 178
 def opensearch():
160 179
     global opensearch_xml