Commit 438fa91c6424af5dc156ea4bbab2bb93d0ae88bf

  • avatar
  • arvind
  • Sat Mar 30 08:59:02 IST 2013
Bug fixes
		- Fixing /submit. request.form['data'] is a stringified JSON. USe json.lods to get the JSON.
fetch.py
(26 / 6)
  
1010import lxml.html
1111import urllib2
1212import StringIO
13import json
1314
15
1416app = Flask(__name__)
1517
1618
4343 return jsonify(ret)
4444
4545
46@app.route('/search', methods=['GET'])
47def search():
48 connection = pymongo.Connection()
49 db = connection['mural']
50 collection = db['data']
51 y = 0
52 ret = {}
53 for i in collection.find():
54 try:
55 if request.args['data'] in i['nodes']:
56 del(i['_id'])
57 ret[y] = i
58 y = y + 1
59 except:
60 pass
61 return render_template('blank.html', content = ret)
4662@app.route('/submit', methods=['POST'])
4763def submit():
4864 c = pymongo.Connection()
4965 db = c['mural']
5066 coll = db['data']
67 requestData = json.loads(request.form['data'])
5168 try:
52 for i in d:
53 coll.insert(request.args['data'])
54 response = make_response()
55 response.status = '200 OK'
56 response.status_code = 200
57 return response
69 for i in requestData:
70 coll.insert(i)
71 response = make_response()
72 response.status = '200 OK'
73 response.status_code = 200
74 return response
5875 except:
5976 response = make_response()
6077 response.status = "500"
105105 root.head.append(link)
106106
107107 return lxml.html.tostring(root)
108
108109
109110#Log the errors, don't depend on apache to log it for you.
110111 fil = FileHandler(os.path.join(os.path.dirname(__file__), 'logme'),mode='a')
  
6060};
6161function onFeatureSelect(feature)
6262{
63 for(var i in ans.ans)
63 for(var i in ans.ans)
6464 {
6565 if(feature.geometry.bounds['left'] == ans.ans[i]['left'] && feature.geometry.bounds['right'] == ans.ans[i]['right'] && feature.geometry.bounds['top'] == ans.ans[i]['top'] && feature.geometry.bounds['bottom'] == ans.ans[i]['bottom'])
6666 {
244244 map.addLayers([box2, box3]);
245245
246246 selectControl = new OpenLayers.Control.SelectFeature(box3,
247 {onSelect: onFeatureSelect});
247 {hover:true, clickout: true, onSelect: onFeatureSelect});
248248
249249 drawControls = {
250250 box : new OpenLayers.Control.DrawFeature(boxes,