From: Thierry Parmentelat Date: Thu, 21 Mar 2013 07:30:05 +0000 (+0100) Subject: when ajax-sending the query back to the manifold proxy, use a json-encoded string X-Git-Tag: myslice-django-0.1-2~42 X-Git-Url: http://git.onelab.eu/?p=unfold.git;a=commitdiff_plain;h=258ce18e803cc727b8fe764e43399bc517d9dae1 when ajax-sending the query back to the manifold proxy, use a json-encoded string --- diff --git a/manifold/js/manifold-query.js b/manifold/js/manifold-query.js index 41ab86fc..7578c0ae 100644 --- a/manifold/js/manifold-query.js +++ b/manifold/js/manifold-query.js @@ -97,10 +97,11 @@ INSERT INTO subject VALUES(field=value) return {'added':added, 'removed':removed}; } - this.to_hash = function() { - return {'action': this.action, 'subject': this.subject, 'timestamp': this.timestamp, - 'filters': this.filters, 'params': this.params, 'fields': this.fields}; - } +// we send queries as a json string now +// this.as_POST = function() { +// return {'action': this.action, 'subject': this.subject, 'timestamp': this.timestamp, +// 'filters': this.filters, 'params': this.params, 'fields': this.fields}; +// } this.analyze_subqueries = function() { /* adapted from the PHP function in com_tophat/includes/query.php */ var q = new ManifoldQuery(); diff --git a/manifold/js/manifold.js b/manifold/js/manifold.js index 763b242e..0ac331b8 100644 --- a/manifold/js/manifold.js +++ b/manifold/js/manifold.js @@ -54,10 +54,13 @@ var manifold = { // Loop through query array and use ajax to send back query_uuid_domids (to frontend) with json jQuery.each(query_uuid_domids, function(index, tuple) { var query=manifold.find_query(tuple.query_uuid); - var hash=query.to_hash(); - if (manifold.asynchroneous_debug) - console.log ("sending POST on " + manifold.proxy_url + " with query= " + query.__repr(query)); - jQuery.post(manifold.proxy_url, {'query': hash}, success_closure(query, tuple.id)); + var query_json=JSON.stringify (query); + if (manifold.asynchroneous_debug) { + console.log ("sending POST on " + manifold.proxy_url + " with query= " + query.__repr()); + } + // not quite sure what happens if we send a string directly, as POST data is named.. + // this gets reconstructed on the proxy side with ManifoldQuery.fill_from_POST + jQuery.post(manifold.proxy_url, {'json':query_json} , success_closure(query, tuple.id)); }) }, diff --git a/manifold/manifoldquery.py b/manifold/manifoldquery.py index 412de674..feed5f5b 100644 --- a/manifold/manifoldquery.py +++ b/manifold/manifoldquery.py @@ -61,18 +61,20 @@ class ManifoldQuery: return result # this builds a ManifoldQuery object from a dict as received from javascript through its ajax request + # we use a json-encoded string - see manifold.js for the sender part # e.g. here's what I captured from the server's output - # incoming POST - def fill_from_POST (self, d): - for key in d.keys(): - for arg in ['action', 'subject', 'filters', 'fields', 'timestamp', 'params']: - if arg in key: - # dirty hack around fields; fields must be a list - if arg == 'fields': - setattr(self, arg, [d[key]]) - else: - setattr(self, arg, d[key]) - break + # manifoldproxy.proxy: request.POST + def fill_from_POST (self, POST_dict): + try: + json_string=POST_dict['json'] + dict=json.loads(json_string) + for (k,v) in dict.iteritems(): + setattr(self,k,v) + except: + print "Could not decode incoming ajax request as a Query, POST=",POST_dict + if (debug): + import traceback + traceback.print_exc() # not used yet .. def analyze_subqueries(self):