コード例 #1
0
    def post(self):
        data = parser.parse_args()

        if ClassModel.find_by_name(data['name']):
            return {
                'message': 'This class {} already exists '.format(data['name'])
            }

        if ClassModel.find_by_code(data['code']):
            return {
                'message': 'This code {} already exists '.format(data['code'])
            }

        #CREATE MODEL DATA FOR SAVE
        new_class = ClassModel(
            name=data['name'],
            code=data['code'],
        )
        try:
            new_class.save_to_db()  #CALL THIS FUNCTION FOR COMMIT DATA

            return {
                'message':
                ' This {} class data  created successfully'.format(
                    data['name'])
            }, 200
        except:
            return {'message': 'Something went wrong'}, 500
コード例 #2
0
 def post(self, name):
     data = Class.parser.parse_args()
     try:
         new_class = ClassModel(name=name,
                                student_limit=data['student_limit'])
         new_class.save_to_db()
         return {
             'message': 'Class {} was created'.format(data['name'])
         }, 201
     except AssertionError as exception_message:
         return {'message': 'Error: {}.'.format(exception_message)}, 400
コード例 #3
0
 def post(self):
     mail = request.args.get('mail')
     classe = request.args.get('class')
     user = UserModel.find_by_mail(mail)
     if user:
         tag = randomtag()
         class_to_add = ClassModel(None, classe, tag, user.id)
         class_to_add.save_to_db()
         class_added = ClassModel.find_by_tag(tag)
         return {"tag": tag}
     return {"message": "user does not exist"}, 400