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();
// 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));
})
},
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 <QueryDict: {u'query[subject]': [u'slice'], u'query[fields][]': [u'slice_hrn'], u'query[timestamp]': [u'latest'], u'query[action]': [u'get']}>
- 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 <QueryDict: {u'json': [u'{"action":"get","subject":"resource","timestamp":"latest","filters":[["slice_hrn","=","ple.inria.omftest"]],"params":[],"fields":["hrn","hostname"],"unique":0,"query_uuid":"436aae70a48141cc826f88e08fbd74b1","analyzed_query":null,"subqueries":{}}']}>
+ 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):