示例#1
0
 def post(self, name):
     if SchoolModel.find_by_name(name):
         return {'message': "Trường '{}' Đã tồn tại".format(name)}, 400
     school = SchoolModel(name)
     try:
         school.save_to_db()
     except:
         return {'message': 'Xảy ra lỗi khi tạo 1 trường học'}, 500
     return school.json(), 201
示例#2
0
 def post(self):
     data = School.parser.parse_args()
     if SchoolModel.find_by_name(data["name"]):
         return {"messages": err_duplicate.format("school")}, 400
     school = SchoolModel(**data)
     try:
         school.save_to_db()
     except:
         return {"messages": err_500}, 500
     return {"messages": noti_201}, 201
示例#3
0
    def post(self, name):
        if SchoolModel.find_by_name(name):
            return {'message': "School '{}' already exists".format(name)}, 400

        school = SchoolModel(name)
        try:
            school.save_to_db()
        except:
            return {
                'message': 'An error occurred while creating the school'
            }, 500

        return school.json(), 201
示例#4
0
 def post(self, schoolName):
     if SchoolModel.find_by_name(schoolName):
         return {
             'message':
             'School with name {} already exists.'.format(schoolName)
         }, 400
     school = SchoolModel(schoolName)
     try:
         school.save_to_db()
     except:
         return {
             'message':
             'An error occurred while saving the school. Database error.'
         }, 500
     return school.json(), 201
示例#5
0
 def get(self, name):
     school = SchoolModel.find_by_name(name)
     if school:
         return school.json()
     return {'message': 'School not found'}, 404
示例#6
0
    def delete(self, name):
        school = SchoolModel.find_by_name(name)
        if school:
            school.delete_from_db()

        return {'message': 'School deleted'}
示例#7
0
 def delete(self, schoolName):
     school = SchoolModel.find_by_name(schoolName)
     if school:
         school.delete_from_db()
     return {'message': 'School deleted. Sorry to see it.'}
示例#8
0
 def get(self, name):
     school = SchoolModel.find_by_name(name)
     if school:
         return school.json()
     return {'message': 'Trường không tồn tại'}, 404