Пример #1
0
    def put(self, stude_id):
        data = Student.parser.parse_args()
        item = StudentModel.find_by_id(stude_id)

        if item is None:
            item = StudentModel(stude_id, **data)
        else:
            item.name = data['name']
            item.course = data['course']
            item.year = data['year']
            item.gender = data['gender']

        item.save_to_db()

        return item.json()
Пример #2
0
    def post(self, stude_id):
        if StudentModel.find_by_id(stude_id):
            return {
                'message': "Student ID '{}' already exist.".format(stude_id)
            }, 400

        data = request.get_json()
        item = StudentModel(stude_id, **data)

        try:
            item.save_to_db()
        except:
            return {"message": "An error occured in inserting the item."}, 500

        return item.json(), 201
Пример #3
0
    def delete(self, stude_id):
        item = StudentModel.find_by_id(stude_id)
        if item:
            item.delete_from_db()

        return {'message': 'Item deleted'}
Пример #4
0
 def get(self, stude_id):
     item = StudentModel.find_by_id(stude_id)
     if item:
         return item.json()
     return {'message': 'Item not found'}, 404