Beispiel #1
0
    def get(self, id):
        obj = DatasourceModel.get_by_id(id)

        if obj:
            s = obj.to_dict()
            return {"data": s, "msg": ""}

        return {"msg": "Item not found!", "data": ""}, 404
Beispiel #2
0
    def delete(self, id):
        obj = DatasourceModel.get_by_id(id)

        if obj:
            try:
                obj.delete()
            except Exception as e:
                print(e)
                return {"msg": "Delete error!", "data": ""}, 404
            return {"data": obj.to_dict(), "msg": ""}
        return {"msg": "Item not found!", "data": ""}, 404
Beispiel #3
0
    def put(self, id):
        obj = DatasourceModel.get_by_id(id)

        if obj:
            self.add_argument("data", type=str, required=True)
            args = self.parser.parse_args()
            data = json.loads(args["data"])
            try:
                obj.update(data)
            except Exception as e:
                print(e)
                return {"msg": "Update error!", "data": ""}, 404
            return {"data": obj.to_dict(), "msg": ""}
        return {"msg": "Item not found!", "data": ""}, 404