Mercurial > p > roundup > code
diff roundup/rest.py @ 5566:2830793d1510 REST-rebased
Added RoundupJSONEncoder
.. to handle classes from roundup
committer: Ralf Schlatterbeck <rsc@runtux.com>
| author | Chau Nguyen <dangchau1991@yahoo.com> |
|---|---|
| date | Wed, 30 Jan 2019 10:26:34 +0100 |
| parents | b3d5085dd04e |
| children | 1af57f9d5bf7 |
line wrap: on
line diff
--- a/roundup/rest.py Wed Jan 30 10:26:34 2019 +0100 +++ b/roundup/rest.py Wed Jan 30 10:26:34 2019 +0100 @@ -50,7 +50,7 @@ raise Unauthorised('Permission to view %s denied' % class_name) class_obj = self.db.getclass(class_name) prop_name = class_obj.labelprop() - result = [{'id': item_id, 'name': class_obj.get(item_id, prop_name)} + result = [{'id': item_id, prop_name: class_obj.get(item_id, prop_name)} for item_id in class_obj.list() if self.db.security.hasPermission('View', self.db.getuid(), class_name, @@ -71,6 +71,7 @@ class_name, prop_name, item_id)] result = dict(result) + result['id'] = item_id return result @@ -187,7 +188,15 @@ except AttributeError: raise NotImplementedError('Method is invalid') finally: - output = json.JSONEncoder().encode(output) + output = RoundupJSONEncoder().encode(output) print "Length: %s - Content(50 char): %s" % (len(output), output[:50]) return output + +class RoundupJSONEncoder(json.JSONEncoder): + def default(self, obj): + try: + result = json.JSONEncoder.default(self, obj) + except TypeError: + result = str(obj) + return result
