comparison roundup/rest.py @ 5660:d8d2b7724292

First attempt at REST-API documentation Also fix operator of patch to be '@op', not 'op'. Example for retire/restore using both, DELETE and PATCH with @op=action.
author Ralf Schlatterbeck <rsc@runtux.com>
date Fri, 22 Mar 2019 11:23:02 +0100
parents 1e51a709431c
children b08a308c273b
comparison
equal deleted inserted replaced
5659:1e51a709431c 5660:d8d2b7724292
784 if not check_etag(class_obj.getnode(item_id), 784 if not check_etag(class_obj.getnode(item_id),
785 obtain_etags(self.client.request.headers, input), 785 obtain_etags(self.client.request.headers, input),
786 class_name, 786 class_name,
787 item_id): 787 item_id):
788 raise PreconditionFailed("Etag is missing or does not match." 788 raise PreconditionFailed("Etag is missing or does not match."
789 "Retreive asset and retry modification if valid.") 789 " Retrieve asset and retry modification if valid.")
790 result = class_obj.set(item_id, **props) 790 result = class_obj.set(item_id, **props)
791 self.db.commit() 791 self.db.commit()
792 except (TypeError, IndexError, ValueError) as message: 792 except (TypeError, IndexError, ValueError) as message:
793 raise ValueError(message) 793 raise ValueError(message)
794 794
839 try: 839 try:
840 if not check_etag(class_obj.getnode(item_id), 840 if not check_etag(class_obj.getnode(item_id),
841 obtain_etags(self.client.request.headers, input), 841 obtain_etags(self.client.request.headers, input),
842 class_name, item_id): 842 class_name, item_id):
843 raise PreconditionFailed("Etag is missing or does not match." 843 raise PreconditionFailed("Etag is missing or does not match."
844 "Retreive asset and retry modification if valid.") 844 " Retrieve asset and retry modification if valid.")
845 result = class_obj.set(item_id, **props) 845 result = class_obj.set(item_id, **props)
846 self.db.commit() 846 self.db.commit()
847 except (TypeError, IndexError, ValueError) as message: 847 except (TypeError, IndexError, ValueError) as message:
848 raise ValueError(message) 848 raise ValueError(message)
849 849
930 if not check_etag(class_obj.getnode(item_id), 930 if not check_etag(class_obj.getnode(item_id),
931 obtain_etags(self.client.request.headers, input), 931 obtain_etags(self.client.request.headers, input),
932 class_name, 932 class_name,
933 item_id): 933 item_id):
934 raise PreconditionFailed("Etag is missing or does not match." 934 raise PreconditionFailed("Etag is missing or does not match."
935 "Retreive asset and retry modification if valid.") 935 " Retrieve asset and retry modification if valid.")
936 936
937 class_obj.retire (item_id) 937 class_obj.retire (item_id)
938 self.db.commit() 938 self.db.commit()
939 result = { 939 result = {
940 'status': 'ok' 940 'status': 'ok'
980 if not check_etag(class_obj.getnode(item_id), 980 if not check_etag(class_obj.getnode(item_id),
981 obtain_etags(self.client.request.headers, input), 981 obtain_etags(self.client.request.headers, input),
982 class_name, 982 class_name,
983 item_id): 983 item_id):
984 raise PreconditionFailed("Etag is missing or does not match." 984 raise PreconditionFailed("Etag is missing or does not match."
985 "Retreive asset and retry modification if valid.") 985 " Retrieve asset and retry modification if valid.")
986 986
987 class_obj.set(item_id, **props) 987 class_obj.set(item_id, **props)
988 self.db.commit() 988 self.db.commit()
989 except (TypeError, IndexError, ValueError) as message: 989 except (TypeError, IndexError, ValueError) as message:
990 raise ValueError(message) 990 raise ValueError(message)
1020 the object 1020 the object
1021 """ 1021 """
1022 if class_name not in self.db.classes: 1022 if class_name not in self.db.classes:
1023 raise NotFound('Class %s not found' % class_name) 1023 raise NotFound('Class %s not found' % class_name)
1024 try: 1024 try:
1025 op = input['op'].value.lower() 1025 op = input['@op'].value.lower()
1026 except KeyError: 1026 except KeyError:
1027 op = self.__default_patch_op 1027 op = self.__default_patch_op
1028 class_obj = self.db.getclass(class_name) 1028 class_obj = self.db.getclass(class_name)
1029 1029
1030 if not check_etag(class_obj.getnode(item_id), 1030 if not check_etag(class_obj.getnode(item_id),
1031 obtain_etags(self.client.request.headers, input), 1031 obtain_etags(self.client.request.headers, input),
1032 class_name, 1032 class_name,
1033 item_id): 1033 item_id):
1034 raise PreconditionFailed("Etag is missing or does not match." 1034 raise PreconditionFailed("Etag is missing or does not match."
1035 "Retreive asset and retry modification if valid.") 1035 " Retrieve asset and retry modification if valid.")
1036 1036
1037 # if patch operation is action, call the action handler 1037 # if patch operation is action, call the action handler
1038 action_args = [class_name + item_id] 1038 action_args = [class_name + item_id]
1039 if op == 'action': 1039 if op == 'action':
1040 # extract action_name and action_args from form fields 1040 # extract action_name and action_args from form fields
1119 the object 1119 the object
1120 """ 1120 """
1121 if class_name not in self.db.classes: 1121 if class_name not in self.db.classes:
1122 raise NotFound('Class %s not found' % class_name) 1122 raise NotFound('Class %s not found' % class_name)
1123 try: 1123 try:
1124 op = input['op'].value.lower() 1124 op = input['@op'].value.lower()
1125 except KeyError: 1125 except KeyError:
1126 op = self.__default_patch_op 1126 op = self.__default_patch_op
1127 1127
1128 if not self.db.security.hasPermission( 1128 if not self.db.security.hasPermission(
1129 'Edit', self.db.getuid(), class_name, attr_name, item_id 1129 'Edit', self.db.getuid(), class_name, attr_name, item_id
1139 if not check_etag(class_obj.getnode(item_id), 1139 if not check_etag(class_obj.getnode(item_id),
1140 obtain_etags(self.client.request.headers, input), 1140 obtain_etags(self.client.request.headers, input),
1141 class_name, 1141 class_name,
1142 item_id): 1142 item_id):
1143 raise PreconditionFailed("Etag is missing or does not match." 1143 raise PreconditionFailed("Etag is missing or does not match."
1144 "Retreive asset and retry modification if valid.") 1144 " Retrieve asset and retry modification if valid.")
1145 1145
1146 props = { 1146 props = {
1147 prop: self.prop_from_arg( 1147 prop: self.prop_from_arg(
1148 class_obj, prop, input['data'].value, item_id 1148 class_obj, prop, input['data'].value, item_id
1149 ) 1149 )

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