row.as_json simplification thanks Alan
This commit is contained in:
@@ -1 +1 @@
|
|||||||
Version 2.4.1-alpha.2+timestamp.2013.01.12.14.03.31
|
Version 2.4.1-alpha.2+timestamp.2013.01.12.14.08.26
|
||||||
|
|||||||
+4
-10
@@ -6689,28 +6689,22 @@ class Row(object):
|
|||||||
del d[k]
|
del d[k]
|
||||||
return d
|
return d
|
||||||
|
|
||||||
def as_json(self, mode='object', default=None, **kwargs):
|
def as_json(self, default=None, **kwargs):
|
||||||
"""
|
"""
|
||||||
serializes the table to a JSON list of objects
|
serializes the table to a JSON list of objects
|
||||||
|
|
||||||
kwargs are passed to .as_dict method
|
kwargs are passed to .as_dict method
|
||||||
|
only "object" mode supported
|
||||||
|
TODO: return array mode with query column order
|
||||||
"""
|
"""
|
||||||
mode = mode.lower()
|
|
||||||
if not mode in ['object', 'array']:
|
|
||||||
raise SyntaxError('Invalid JSON serialization mode: %s' % mode)
|
|
||||||
|
|
||||||
multi = any([isinstance(v, self.__class__) for v in self.values()])
|
multi = any([isinstance(v, self.__class__) for v in self.values()])
|
||||||
item = dict()
|
item = dict()
|
||||||
|
|
||||||
if multi:
|
if multi:
|
||||||
for k, v in self.as_dict(**kwargs).iteritems():
|
for v in self.as_dict(**kwargs).values():
|
||||||
item.update(v)
|
item.update(v)
|
||||||
else:
|
else:
|
||||||
item = self.as_dict(**kwargs)
|
item = self.as_dict(**kwargs)
|
||||||
|
|
||||||
if mode != 'object':
|
|
||||||
item = item.values()
|
|
||||||
|
|
||||||
if have_serializers:
|
if have_serializers:
|
||||||
return serializers.json(item,
|
return serializers.json(item,
|
||||||
default=default or
|
default=default or
|
||||||
|
|||||||
Reference in New Issue
Block a user