configure manifold server in myslice/config.py
[myslice.git] / engine / manifold_query.py
diff --git a/engine/manifold_query.py b/engine/manifold_query.py
new file mode 100644 (file)
index 0000000..8a5690f
--- /dev/null
@@ -0,0 +1,48 @@
+import json
+
+# xxx php has uniqid, need to find a module for that
+counter=1
+def uniqid (): global counter; counter += 1; return counter
+
+class ManifoldQuery:
+
+    def __init__ (self, action=None, method=None, timestamp='now',
+                  filters=[], params=[], fields=[],
+                  sort=None, limit=None, offset=None,
+                  ):
+        self.uuid=uniqid()
+        # settable
+        self.action=action
+        self.method=method
+        self.timestamp=timestamp
+        self.filters=filters
+        self.params=params
+        self.fields=fields
+        self.sort=sort
+        self.limit=limit
+        self.offset=offset
+        # internal data
+        self.analyzed_query=None
+        self.subqueries = {}
+
+    def to_json (self):
+        uuid=self.uuid
+        a=self.action
+        m=self.method
+        t=self.timestamp
+        f=json.dumps (self.filters)
+        p=json.dumps (self.params)
+        c=json.dumps (self.fields)
+        # xxx unique can be removed, but for now we pad the js structure
+        unique=0
+
+        # subqueries is a dictionary method:query
+        sq=", ".join ( [ "'%s':%s" % (method, subquery.to_json())
+                      for (method, subquery) in self.subqueries.iteritems()])
+        
+        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()
+
+    
+