Query trip: bridge the gap between FE nad BE
[unfold.git] / engine / manifoldquery.py
index b8f594e..47b261f 100644 (file)
@@ -36,10 +36,27 @@ class ManifoldQuery:
         # xxx unique can be removed, but for now we pad the js structure
         unique=0
 
+        aq = self.analyzed_query.to_json() if self.analyzed_query else 'null'
         # subqueries is a dictionary method:query
-        sq=", ".join ( [ "'%s':%s" % (method, subquery.to_json())
+        if not self.subqueries: 
+            sq="{}"
+        else:
+            sq=", ".join ( [ "'%s':%s" % (method, subquery.to_json())
                       for (method, subquery) in self.subqueries.iteritems()])
+            sq="{%s}"%sq
         
-        aq = self.analyzed_query.to_json() if self.analyzed_query else 'null'
-        
-        return "new Query('%(a)s', '%(m)s', '%(t)s', %(f)s, %(p)s, %(c)s, %(unique)s, '%(uuid)s', %(aq)s, {{%(sq)s}})"%locals()
+        return """ new Query('%(a)s', '%(m)s', '%(t)s', %(f)s, %(p)s, %(c)s, %(unique)s, '%(uuid)s', %(aq)s, %(sq)s)"""%locals()
+    
+    # 4amine
+    # xxx
+    # this should build an object from a dict as received from javascript
+    # to see an example just look at the server's output
+    # incoming POST <QueryDict: {u'query[method]': [u'slice'], u'query[fields][]': [u'slice_hrn'], u'query[ts]': [u'latest'], u'query[action]': [u'get']}>
+    def fill_from_dict (self, d):
+        # mandatory...
+        self.action=d['query[action]']
+        self.method=d['query[method]']
+        self.fields=[d['query[fields][]']]
+        self.timestamp=d['query[ts]'] 
+        #self.filters=d['filters']
+        #self.params=d['params']