Exemple #1
0
    def put(self, movie_id):
        params = request.json
        print(params)
        title = params.get('title')
        video_link = params.get('videoLink')
        info = params.get('info')
        image_link = params.get('imageLink')
        star = params.get('star')
        play_num = params.get('playNum')
        comment_num = params.get('commentNum')
        tag_id = params.get('tagId')
        area = params.get('area')
        release_time = params.get('releaseDate')
        length = params.get('length')
        addtime = datetime.datetime.now()

        movie = self._is_id_existed(movie_id=movie_id)
        if movie is not None:
            movie.title = title
            movie.url = video_link
            movie.info = info
            movie.logo = image_link
            movie.star = star
            movie.playnum = play_num
            movie.commentnum = comment_num
            movie.area = area
            # movie.release_time = release_time
            movie.length = length
            db.session.commit()
            return make_response(code=0, msg='Success')

        return make_response(code=1, msg='该电影不存在')
Exemple #2
0
    def put(self, tag_id):
        params = request.json
        resp_data = {}
        if self._is_id_existed(tag_id) is None:
            return make_response(code=1, msg="该标签不存在!")

        if self._is_name_existed(params['name']) is not None:
            return make_response(code=1, msg='不能添加已存在的标签')

        try:
            db.session.query(Tag).filter_by(id=tag_id).update({'name': params['name']})
            db.session.commit()
            resp_data.update({
                'code': 0,
                'msg': 'Success'
            })
        except Exception as err:
            print('[error]:', err)
            resp_data.update({
                'code': 1,
                'msg': str(err)
            })
        finally:
            db.session.close()
        return make_response(code=resp_data['code'], msg=resp_data['msg'])
Exemple #3
0
def single_department(department_id):
    """
    获取、更新或删除单个部门组织
    :param department_id: 部门id
    :return:
    """
    department = Department.query.filter_by(id=department_id).first_or_404(
        description="部门ID不存在")
    if request.method == "GET":
        logging.info("get a department info: %s" % department.dumps())
        return make_response(data=department.dumps_detail())

    if request.method == "PUT":
        name, parent_id = department_request_handler(request, department)
        old_department_info = department
        department.name = name
        department.parent_id = parent_id
        try:
            db.session.commit()
        except Exception:
            logging.error(
                "update department error, department info: %s, old department info: %s. \n traceback error: %s"
                % (department.dumps(), old_department_info.dumps(),
                   traceback.format_exc()))
            abort(500)
        logging.info(
            "update a department info: %s, before update the department info: %s"
            % (department.dumps(), old_department_info.dumps()))
        return make_response(data=department.dumps_detail())

    if request.method == "DELETE":
        with db.auto_commit():
            department.delete()
        logging.info("delete a department: %s" % department)
        return make_response()
Exemple #4
0
def single_emp(employee_id):
    """
    根据员工id获取,更新,删除员工信息
    :param employee_id: 员工ID
    :return:
    """
    employee = Employee.query.filter_by(id=employee_id).first_or_404(description="所查询的员工ID不存在")
    if request.method == "GET":
        return make_response(data=employee.dumps())

    if request.method == "PUT":
        name, gender, department = employee_request_handler(request)
        old_employee_info = employee
        employee.name = name
        employee.gender = gender
        employee.department_id = department.id

        try:
            db.session.commit()
        except Exception:
            logging.error(
                "update employee error, employee info: %s, old employee info: %s. \n traceback error: %s" % (
                    employee.dumps(), old_employee_info.dumps(), traceback.format_exc()))
            abort(500)
        logging.info(
            "update a employee info: %s, before update the employee info: %s" % (
                employee.dumps(), old_employee_info.dumps()))
        return make_response(data=employee.dumps())

    if request.method == "DELETE":
        with db.auto_commit():
            employee.delete()
        return make_response()
Exemple #5
0
 def delete(self, movie_id):
     movie = self._is_id_existed(movie_id=movie_id)
     if movie is not None:
         db.session.delete(movie)
         db.session.commit()
         return make_response(code=0, msg='Success')
     else:
         return make_response(code=1, msg='该电影不存在!')
Exemple #6
0
 def delete(self, role_id):
     role = self._is_id_existed(role_id=role_id)
     if role is not None:
         db.session.delete(role)
         db.session.commit()
         return make_response(code=0, msg='Success')
     else:
         return make_response(code=1, msg='该角色不存在!')
Exemple #7
0
 def delete(self, tag_id):
     tag = self._is_id_existed(tag_id)
     if tag is not None:
         db.session.delete(tag)
         db.session.commit()
         return make_response(code=0, msg='Success')
     else:
         return make_response(code=1, msg="该标签不存在!")
 def delete(self, preview_id):
     preview = self._is_id_existed(preview_id=preview_id)
     if preview is not None:
         db.session.delete(preview)
         db.session.commit()
         return make_response(code=0, msg='Success')
     else:
         return make_response(code=1, msg='该预告不存在!')
Exemple #9
0
 def delete(self, auth_id):
     auth = self._is_id_existed(auth_id=auth_id)
     if auth is not None:
         db.session.delete(auth)
         db.session.commit()
         return make_response(code=0, msg='Success')
     else:
         return make_response(code=1, msg='该权限不存在!')
Exemple #10
0
def submission_list():
    try:
        list_of_submissions = SubmissionController.list_submissions(request.values)
    except (ValueError, KeyError) as e:
        return make_response(e.args[0]), 400
    except Exception as e:
        return make_response('Server Error'), 500
    
    return make_response('Success', list_of_submissions), 200
Exemple #11
0
def user_new():
    try:
        UserController.new(request.form)
    except (ValueError, KeyError) as e:
        return make_response(e.args[0]), 400
    except Exception as e:
        return make_response('Server Error'), 500
    
    return make_response('Success'), 200
Exemple #12
0
def course_show():
    try:
        courses = CourseController.show_courses(request.args)
    except (ValueError, KeyError) as e:
        return make_response(e.args[0]), 400
    except Exception as e:
        return make_response('Server Error'), 500

    return make_response('Success', courses), 200
 def put(self, preview_id):
     params = request.json
     preview = self._is_id_existed(preview_id=preview_id)
     if preview is not None:
         db.session.query(Preview).filter_by(id=preview_id).update({'title': params['title'], 'logo': params['logoLink']})
         db.session.commit()
         return make_response(code=0, msg='Success')
     else:
         return make_response(code=1, msg='该预告不存在!')
Exemple #14
0
def check_run():
    try:
        url = ChecksController.run(request.form)
    except (ValueError, KeyError) as e:
        return make_response(e.args[0]), 400
    except Exception as e:
        return make_response('Server Error'), 500
    
    return make_response('Success', url), 200
Exemple #15
0
def submission_new():
    try:
        duplicate_entries = SubmissionController.new(request.form, request.files)
    except (ValueError, KeyError) as e:
        return make_response(e.args[0]), 400
    except Exception as e:
        return make_response('Server Error'), 500
    
    return make_response('Success', duplicate_entries), 200
Exemple #16
0
def user_login():
    try:
        user_data = UserController.login(request.get_json())
    except (ValueError, KeyError) as e:
        print(e)
        return make_response(e.args[0]), 400
    except Exception as e:
        return make_response('Server Error'), 500
    
    return make_response('Success',user_data), 200
Exemple #17
0
def course_new():
    try:
        print(request.get_json())
        CourseController.new(request.get_json())
    except (ValueError, KeyError) as e:
        return make_response(e.args[0]), 400
    except Exception as e:
        return make_response('Server Error'), 500

    return make_response('Success'), 200
Exemple #18
0
def checks_show():
    try:
        checks = ChecksController.show_checks(request.args)
    except (ValueError, KeyError) as e:
        print(e.args[0])
        return make_response(e.args[0]), 400
    except Exception as e:
        return make_response('Server Error'), 500

    return make_response('Success', checks), 200
Exemple #19
0
 def post(self):
     args = parser.parse_args()
     name = args['name']
     tag = Tag.query.filter_by(name=name).first()
     if tag is None:
         db.session.add(Tag(name=name, addtime=datetime.datetime.now()))
         db.session.commit()
         return make_response(code=0)
     else:
         return make_response(code=1, msg='该标签已经存在!')
 def post(self):
     params = request.json
     title = params.get('title')
     logo_link = params.get('logoLink')
     if self._is_title_existed(title=title) is None:
         db.session.add(Preview(title=title, logo=logo_link))
         db.session.commit()
         return make_response(code=0)
     else:
         return make_response(code=1, msg='不能添加重复预告')
Exemple #21
0
def reports_show():
    try:
        reports = ReportsController.show_reports(request.args)
        print(reports)
    except (ValueError, KeyError) as e:
        print(e.args[0])
        return make_response(e.args[0]), 400
    except Exception as e:
        return make_response('Server Error'), 500

    return make_response('Success', reports), 200
Exemple #22
0
def path_new():
    try:
        PathsController.new(request.form, request.files)
    except (ValueError, KeyError) as e:
        print("error",e)
        return make_response(e.args[0]), 400
    except Exception as e:
        print(e)
        return make_response('Server Error'), 500
    
    return make_response('Success'), 200
Exemple #23
0
 def post(self):
     params = request.json
     name = params['name']
     url = params['url']
     auth = self._is_name_existed(name=name)
     if auth is None:
         db.session.add(Auth(name=name, url=url))
         db.session.commit()
         return make_response(code=0, msg='Success')
     else:
         return make_response(code=1, msg='该权限已存在')
Exemple #24
0
    def get(self, movie_id):
        resp = Auth.identify(request.headers)
        if not resp['allow_access']:
            return make_response(code=1, msg=resp['msg'])

        user_id = resp['user_id']
        count = Moviecol.query.filter(
            and_(Moviecol.movie_id == movie_id,
                 Moviecol.user_id == user_id)).count()
        return make_response(code=0,
                             data={'isCollected': count > 0},
                             msg='Success')
Exemple #25
0
 def post(self):
     params = request.json
     name = params['name']
     password = params['password']
     admin = Admin.query.filter_by(name=name).first()
     print(admin)
     if admin is not None:
         if admin.pwd == password:
             return make_response(code=0, msg='Success')
         return make_response(code=1, msg='账号或者密码错误!')
     else:
         return make_response(code=0, msg='该管理员不存在!')
Exemple #26
0
 def put(self, auth_id):
     params = request.json
     auth = self._is_id_existed(auth_id=auth_id)
     if auth is not None:
         db.session.query(Auth).filter_by(id=auth_id).update({
             'name':
             params['name'],
             'url':
             params['url']
         })
         db.session.commit()
         return make_response(code=0, msg='Success')
     else:
         return make_response(code=1, msg='该权限不存在!')
Exemple #27
0
 def put(self, role_id):
     parmas = request.json
     role = self._is_id_existed(role_id=role_id)
     if role is not None:
         db.session.query(Role).filter(id=role_id).update({
             'name':
             parmas['name'],
             'auths':
             ';'.join(parmas['authList'])
         })
         db.session.commit()
         return make_response(code=0, msg='Success')
     else:
         return make_response(code=1, msg='该角色不存在!')
Exemple #28
0
 def post(self):
     params = request.json
     name = params['name']
     auth_list = params['authList']
     role = self._is_name_existed(name=name)
     if role is None:
         db.session.add(
             Role(name=name,
                  auths=';'.join([str(auth) for auth in auth_list]),
                  addtime=datetime.datetime.now()))
         db.session.commit()
         return make_response(code=0, msg='Success')
     else:
         return make_response(code=1, msg='该角色已存在!')
Exemple #29
0
 def get(self, movie_id):
     movie = Movie.query.get(movie_id)
     if movie is not None:
         return make_response(code=0,
                              data={
                                  'id': movie.id,
                                  'title': movie.title,
                                  'imageLink': movie.logo,
                                  'videoLink': movie.url,
                                  'length': movie.length,
                                  'area': movie.area,
                                  'releaseTime': movie.release_time,
                                  'info': movie.info,
                              },
                              msg='Success')
     return make_response(code=1, msg='该电影不存在!')
Exemple #30
0
 def post(self):
     params = request.json
     name = params['name']
     pwd = params['password']
     role_id = params['roleId']
     admin = Admin.query.filter_by(name=name).first()
     if admin is None:
         db.session.add(
             Admin(name=name,
                   pwd=pwd,
                   addtime=datetime.datetime.now(),
                   role_id=role_id))
         db.session.commit()
         return make_response(code=0, msg='Success')
     else:
         return make_response(code=1, msg='该管理员已存在!')