fix json'ing a manyfold query
authorThierry Parmentelat <thierry.parmentelat@inria.fr>
Mon, 4 Mar 2013 15:17:49 +0000 (16:17 +0100)
committerThierry Parmentelat <thierry.parmentelat@inria.fr>
Mon, 4 Mar 2013 15:17:49 +0000 (16:17 +0100)
engine/manifoldquery.py

index b8f594e..188a1d4 100644 (file)
@@ -36,10 +36,13 @@ 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()