def post(self):
"""Post an item to the DB with the request.data JSON object.
:arg self: The class of the object to be inserted
:returns: The JSON item stored in the DB
"""
try:
self.valid_args()
data = self._file_upload(request)
if data is None:
data = json.loads(request.data)
self._forbidden_attributes(data)
inst = self._create_instance_from_request(data)
repo = repos[self.__class__.__name__]['repo']
save_func = repos[self.__class__.__name__]['save']
getattr(repo, save_func)(inst)
self._log_changes(None, inst)
return json.dumps(inst.dictize())
except Exception as e:
return error.format_exception(
e,
target=self.__class__.__name__.lower(),
action='POST')
评论列表
文章目录