From 438fa91c6424af5dc156ea4bbab2bb93d0ae88bf Mon Sep 17 00:00:00 2001 From: Arvind Date: Sat, 30 Mar 2013 08:59:02 +0530 Subject: [PATCH] Bug fixes - Fixing /submit. request.form['data'] is a stringified JSON. USe json.lods to get the JSON. --- fetch.py | 32 ++++++++++++++++++++++++++------ static/myVector.js | 5 +++-- 2 files changed, 29 insertions(+), 8 deletions(-) diff --git a/fetch.py b/fetch.py index 04f7b65..b1249ed 100644 --- a/fetch.py +++ b/fetch.py @@ -10,6 +10,8 @@ import os import lxml.html import urllib2 import StringIO +import json + app = Flask(__name__) @@ -41,18 +43,35 @@ def fetch(): return jsonify(ret) +@app.route('/search', methods=['GET']) +def search(): + connection = pymongo.Connection() + db = connection['mural'] + collection = db['data'] + y = 0 + ret = {} + for i in collection.find(): + try: + if request.args['data'] in i['nodes']: + del(i['_id']) + ret[y] = i + y = y + 1 + except: + pass + return render_template('blank.html', content = ret) @app.route('/submit', methods=['POST']) def submit(): c = pymongo.Connection() db = c['mural'] coll = db['data'] + requestData = json.loads(request.form['data']) try: - for i in d: - coll.insert(request.args['data']) - response = make_response() - response.status = '200 OK' - response.status_code = 200 - return response + for i in requestData: + coll.insert(i) + response = make_response() + response.status = '200 OK' + response.status_code = 200 + return response except: response = make_response() response.status = "500" @@ -87,6 +106,7 @@ def SWeeText(): return lxml.html.tostring(root) + #Log the errors, don't depend on apache to log it for you. fil = FileHandler(os.path.join(os.path.dirname(__file__), 'logme'),mode='a') fil.setLevel(logging.ERROR) diff --git a/static/myVector.js b/static/myVector.js index 94e74b7..f67cd1c 100644 --- a/static/myVector.js +++ b/static/myVector.js @@ -60,7 +60,7 @@ var handler={ }; function onFeatureSelect(feature) { - for(var i in ans.ans) + for(var i in ans.ans) { 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']) { @@ -244,7 +244,7 @@ function init(url){ map.addLayers([box2, box3]); selectControl = new OpenLayers.Control.SelectFeature(box3, - {onSelect: onFeatureSelect}); + {hover:true, clickout: true, onSelect: onFeatureSelect}); drawControls = { box : new OpenLayers.Control.DrawFeature(boxes, @@ -475,3 +475,4 @@ var config = { 'postTweetUrl':'http://192.168.100.14:5001', 'indexer':'http://localhost:5000' } + -- 1.7.10.4