when ajax-sending the query back to the manifold proxy, use a json-encoded string
authorThierry Parmentelat <thierry.parmentelat@inria.fr>
Thu, 21 Mar 2013 07:30:05 +0000 (08:30 +0100)
committerThierry Parmentelat <thierry.parmentelat@inria.fr>
Thu, 21 Mar 2013 07:30:05 +0000 (08:30 +0100)
manifold/js/manifold-query.js
manifold/js/manifold.js
manifold/manifoldquery.py

index 41ab86f..7578c0a 100644 (file)
@@ -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();
index 763b242..0ac331b 100644 (file)
@@ -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));
        })
            },
 
index 412de67..feed5f5 100644 (file)
@@ -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 <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):