3 # xxx php has uniqid, need to find a module for that
5 def uniqid (): global counter; counter += 1; return counter
9 def __init__ (self, action=None, method=None, timestamp='now',
10 filters=[], params=[], fields=[],
11 sort=None, limit=None, offset=None,
17 self.timestamp=timestamp
25 self.analyzed_query=None
33 f=json.dumps (self.filters)
34 p=json.dumps (self.params)
35 c=json.dumps (self.fields)
36 # xxx unique can be removed, but for now we pad the js structure
39 aq = self.analyzed_query.to_json() if self.analyzed_query else 'null'
40 # subqueries is a dictionary method:query
41 if not self.subqueries:
44 sq=", ".join ( [ "'%s':%s" % (method, subquery.to_json())
45 for (method, subquery) in self.subqueries.iteritems()])
48 return """ new Query('%(a)s', '%(m)s', '%(t)s', %(f)s, %(p)s, %(c)s, %(unique)s, '%(uuid)s', %(aq)s, %(sq)s)"""%locals()
52 # this should build an object from a dict as received from javascript
53 # to see an example just look at the server's output
54 # incoming POST <QueryDict: {u'query[method]': [u'slice'], u'query[fields][]': [u'slice_hrn'], u'query[ts]': [u'latest'], u'query[action]': [u'get']}>
55 def fill_from_dict (self, d):
57 self.action=d['query[action]']
58 self.method=d['query[method]']
59 self.fields=[d['query[fields][]']]
60 self.timestamp=d['query[ts]']
61 #self.filters=d['filters']
62 #self.params=d['params']