comparison roundup/rest.py @ 5600:e2c74d8121f3 REST-rebased

Update resource links .. to match the recently URI changes committer: Ralf Schlatterbeck <rsc@runtux.com>
author Chau Nguyen <dangchau1991@yahoo.com>
date Wed, 30 Jan 2019 10:26:35 +0100
parents a76d88673375
children c40d04915e23
comparison
equal deleted inserted replaced
5599:a76d88673375 5600:e2c74d8121f3
236 self.actions.update({'retire': actions.Retire}) 236 self.actions.update({'retire': actions.Retire})
237 237
238 protocol = 'http' 238 protocol = 'http'
239 host = self.client.env['HTTP_HOST'] 239 host = self.client.env['HTTP_HOST']
240 tracker = self.client.env['TRACKER_NAME'] 240 tracker = self.client.env['TRACKER_NAME']
241 self.base_path = '%s://%s/%s/rest/' % (protocol, host, tracker) 241 self.base_path = '%s://%s/%s/rest' % (protocol, host, tracker)
242 self.data_path = self.base_path + '/data'
242 243
243 def props_from_args(self, cl, args, itemid=None): 244 def props_from_args(self, cl, args, itemid=None):
244 """Construct a list of properties from the given arguments, 245 """Construct a list of properties from the given arguments,
245 and return them after validation. 246 and return them after validation.
246 247
391 'View', self.db.getuid(), class_name 392 'View', self.db.getuid(), class_name
392 ): 393 ):
393 raise Unauthorised('Permission to view %s denied' % class_name) 394 raise Unauthorised('Permission to view %s denied' % class_name)
394 395
395 class_obj = self.db.getclass(class_name) 396 class_obj = self.db.getclass(class_name)
396 class_path = self.base_path + class_name 397 class_path = '%s/%s/' % (self.data_path, class_name)
397 398
398 # Handle filtering and pagination 399 # Handle filtering and pagination
399 filter_props = {} 400 filter_props = {}
400 page = { 401 page = {
401 'size': None, 402 'size': None,
492 except KeyError, msg: 493 except KeyError, msg:
493 raise UsageError("%s field not valid" % msg) 494 raise UsageError("%s field not valid" % msg)
494 result = { 495 result = {
495 'id': item_id, 496 'id': item_id,
496 'type': class_name, 497 'type': class_name,
497 'link': self.base_path + class_name + item_id, 498 'link': '%s/%s/%s' % (self.data_path, class_name, item_id),
498 'attributes': dict(result) 499 'attributes': dict(result)
499 } 500 }
500 501
501 return 200, result 502 return 200, result
502 503
535 class_obj = self.db.getclass(class_name) 536 class_obj = self.db.getclass(class_name)
536 data = class_obj.get(item_id, attr_name) 537 data = class_obj.get(item_id, attr_name)
537 result = { 538 result = {
538 'id': item_id, 539 'id': item_id,
539 'type': type(data), 540 'type': type(data),
540 'link': "%s%s%s/%s" % 541 'link': "%s/%s/%s/%s" %
541 (self.base_path, class_name, item_id, attr_name), 542 (self.data_path, class_name, item_id, attr_name),
542 'data': data 543 'data': data
543 } 544 }
544 545
545 return 200, result 546 return 200, result
546 547
595 raise ValueError(message) 596 raise ValueError(message)
596 except KeyError, msg: 597 except KeyError, msg:
597 raise UsageError("Must provide the %s property." % msg) 598 raise UsageError("Must provide the %s property." % msg)
598 599
599 # set the header Location 600 # set the header Location
600 link = self.base_path + class_name + item_id 601 link = '%s/%s/%s' % (self.data_path, class_name, item_id)
601 self.client.setHeader("Location", link) 602 self.client.setHeader("Location", link)
602 603
603 # set the response body 604 # set the response body
604 result = { 605 result = {
605 'id': item_id, 606 'id': item_id,
648 raise ValueError(message) 649 raise ValueError(message)
649 650
650 result = { 651 result = {
651 'id': item_id, 652 'id': item_id,
652 'type': class_name, 653 'type': class_name,
653 'link': self.base_path + class_name + item_id, 654 'link': '%s/%s/%s' % (self.data_path, class_name, item_id),
654 'attribute': result 655 'attribute': result
655 } 656 }
656 return 200, result 657 return 200, result
657 658
658 @Routing.route("/data/<:class_name>/<:item_id>/<:attr_name>", 'PUT') 659 @Routing.route("/data/<:class_name>/<:item_id>/<:attr_name>", 'PUT')
699 raise ValueError(message) 700 raise ValueError(message)
700 701
701 result = { 702 result = {
702 'id': item_id, 703 'id': item_id,
703 'type': class_name, 704 'type': class_name,
704 'link': self.base_path + class_name + item_id, 705 'link': '%s/%s/%s' % (self.data_path, class_name, item_id),
705 'attribute': result 706 'attribute': result
706 } 707 }
707 708
708 return 200, result 709 return 200, result
709 710
883 result = action.execute(*action_args) 884 result = action.execute(*action_args)
884 885
885 result = { 886 result = {
886 'id': item_id, 887 'id': item_id,
887 'type': class_name, 888 'type': class_name,
888 'link': self.base_path + class_name + item_id, 889 'link': '%s/%s/%s' % (self.data_path, class_name, item_id),
889 'result': result 890 'result': result
890 } 891 }
891 else: 892 else:
892 # else patch operation is processing data 893 # else patch operation is processing data
893 props = self.props_from_args(class_obj, input.value, item_id) 894 props = self.props_from_args(class_obj, input.value, item_id)
912 raise ValueError(message) 913 raise ValueError(message)
913 914
914 result = { 915 result = {
915 'id': item_id, 916 'id': item_id,
916 'type': class_name, 917 'type': class_name,
917 'link': self.base_path + class_name + item_id, 918 'link': '%s/%s/%s' % (self.data_path, class_name, item_id),
918 'attribute': result 919 'attribute': result
919 } 920 }
920 return 200, result 921 return 200, result
921 922
922 @Routing.route("/data/<:class_name>/<:item_id>/<:attr_name>", 'PATCH') 923 @Routing.route("/data/<:class_name>/<:item_id>/<:attr_name>", 'PATCH')
978 raise ValueError(message) 979 raise ValueError(message)
979 980
980 result = { 981 result = {
981 'id': item_id, 982 'id': item_id,
982 'type': class_name, 983 'type': class_name,
983 'link': self.base_path + class_name + item_id, 984 'link': '%s/%s/%s' % (self.data_path, class_name, item_id),
984 'attribute': result 985 'attribute': result
985 } 986 }
986 return 200, result 987 return 200, result
987 988
988 @Routing.route("/data/<:class_name>", 'OPTIONS') 989 @Routing.route("/data/<:class_name>", 'OPTIONS')

Roundup Issue Tracker: http://roundup-tracker.org/