Commit 438fa91c6424af5dc156ea4bbab2bb93d0ae88bf
Bug fixes
- Fixing /submit. request.form['data'] is a stringified JSON. USe json.lods to get the JSON.
| | | | 10 | import lxml.html | 10 | import lxml.html |
---|
11 | import urllib2 | 11 | import urllib2 |
---|
12 | import StringIO | 12 | import StringIO |
---|
| | 13 | import json |
---|
13 | | 14 | |
---|
| | 15 | |
---|
14 | app = Flask(__name__) | 16 | app = Flask(__name__) |
---|
15 | | 17 | |
---|
16 | | 18 | |
---|
… | | … | |
---|
43 | return jsonify(ret) | 43 | return jsonify(ret) |
---|
44 | | 44 | |
---|
45 | | 45 | |
---|
| | 46 | @app.route('/search', methods=['GET']) |
---|
| | 47 | def 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) |
---|
46 | @app.route('/submit', methods=['POST']) | 62 | @app.route('/submit', methods=['POST']) |
---|
47 | def submit(): | 63 | def submit(): |
---|
48 | c = pymongo.Connection() | 64 | c = pymongo.Connection() |
---|
49 | db = c['mural'] | 65 | db = c['mural'] |
---|
50 | coll = db['data'] | 66 | coll = db['data'] |
---|
| | 67 | requestData = json.loads(request.form['data']) |
---|
51 | try: | 68 | try: |
---|
52 | for i in d: | | for i in d: |
---|
53 | coll.insert(request.args['data']) | | coll.insert(request.args['data']) |
---|
54 | response = make_response() | | response = make_response() |
---|
55 | response.status = '200 OK' | | response.status = '200 OK' |
---|
56 | response.status_code = 200 | | response.status_code = 200 |
---|
57 | return response | | 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 |
---|
58 | except: | 75 | except: |
---|
59 | response = make_response() | 76 | response = make_response() |
---|
60 | response.status = "500" | 77 | response.status = "500" |
---|
… | | … | |
---|
105 | root.head.append(link) | 105 | root.head.append(link) |
---|
106 | | 106 | |
---|
107 | return lxml.html.tostring(root) | 107 | return lxml.html.tostring(root) |
---|
| | 108 | |
---|
108 | | 109 | |
---|
109 | #Log the errors, don't depend on apache to log it for you. | 110 | #Log the errors, don't depend on apache to log it for you. |
---|
110 | fil = FileHandler(os.path.join(os.path.dirname(__file__), 'logme'),mode='a') | 111 | fil = FileHandler(os.path.join(os.path.dirname(__file__), 'logme'),mode='a') |
---|
| | | | 60 | }; | 60 | }; |
---|
61 | function onFeatureSelect(feature) | 61 | function onFeatureSelect(feature) |
---|
62 | { | 62 | { |
---|
63 | for(var i in ans.ans) | | for(var i in ans.ans) |
---|
| | 63 | for(var i in ans.ans) | 64 | { | 64 | { |
---|
65 | 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']) | 65 | 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']) |
---|
66 | { | 66 | { |
---|
… | | … | |
---|
244 | map.addLayers([box2, box3]); | 244 | map.addLayers([box2, box3]); |
---|
245 | | 245 | |
---|
246 | selectControl = new OpenLayers.Control.SelectFeature(box3, | 246 | selectControl = new OpenLayers.Control.SelectFeature(box3, |
---|
247 | {onSelect: onFeatureSelect}); | | {onSelect: onFeatureSelect}); |
---|
| | 247 | {hover:true, clickout: true, onSelect: onFeatureSelect}); | 248 | | 248 | |
---|
249 | drawControls = { | 249 | drawControls = { |
---|
250 | box : new OpenLayers.Control.DrawFeature(boxes, | 250 | box : new OpenLayers.Control.DrawFeature(boxes, |
---|