Mercurial > p > roundup > code
diff roundup/rest.py @ 5570:8431a872b008 REST-rebased
Response is now following the design format
Successful response is now following the design format
Fix a bug with exception error message
committer: Ralf Schlatterbeck <rsc@runtux.com>
| author | Chau Nguyen <dangchau1991@yahoo.com> |
|---|---|
| date | Wed, 30 Jan 2019 10:26:34 +0100 |
| parents | 2718aeb55ffa |
| children | a2eb27c51a92 |
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 @@ -82,7 +82,8 @@ 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, prop_name: class_obj.get(item_id, prop_name)} + class_path = self.base_path + class_name + result = [{'id': item_id, 'link': class_path + item_id} for item_id in class_obj.list() if self.db.security.hasPermission('View', self.db.getuid(), class_name, @@ -102,8 +103,12 @@ if self.db.security.hasPermission('View', self.db.getuid(), class_name, prop_name, item_id)] - result = dict(result) - result['id'] = item_id + result = { + 'id': item_id, + 'type': class_name, + 'link': self.base_path + class_name + item_id, + 'attributes': dict(result) + } return result @@ -135,7 +140,10 @@ except (TypeError, IndexError, ValueError), message: raise UsageError(message) - result = {id: item_id} + result = { + 'id': item_id, + 'link': self.base_path + class_name + item_id + } return result def post_element(self, class_name, item_id, input): @@ -159,7 +167,12 @@ except (TypeError, IndexError, ValueError), message: raise UsageError(message) - result['id'] = item_id + result = { + 'id': item_id, + 'type': class_name, + 'link': self.base_path + class_name + item_id, + 'attribute': result + } return result def delete_collection(self, class_name, input): @@ -174,11 +187,15 @@ raise Unauthorised('Permission to delete %s %s denied' % (class_name, item_id)) + count = len(class_obj.list()) for item_id in class_obj.list(): self.db.destroynode(class_name, item_id) self.db.commit() - result = {"status": "ok"} + result = { + 'status': 'ok', + 'count': count + } return result @@ -190,7 +207,9 @@ self.db.destroynode(class_name, item_id) self.db.commit() - result = {"status": "ok"} + result = { + 'status': 'ok' + } return result @@ -224,8 +243,8 @@ output = error_obj(403, msg) except (hyperdb.DesignatorError, UsageError), msg: output = error_obj(400, msg) - except (AttributeError, Reject): - output = error_obj(405, 'Method Not Allowed') + except (AttributeError, Reject), msg: + output = error_obj(405, 'Method Not Allowed. ' + str(msg)) except NotImplementedError: output = error_obj(402, 'Method is under development') # nothing to pay, just a mark for debugging purpose
