def get_exams(upload_user): #查询上传用户试卷记录 query = Exam.query.\ filter(Exam.upload_user == upload_user, Exam.state >= EXAM_STATUS['审核不通过']).\ order_by(Exam.created_at.desc(), Exam.state) if request.args.get('name'): query = query.filter(Exam.name.like('%{}%'.format(request.args.get('name')))) if request.args.get('subject'): query = query.filter(Exam.subject==request.args.get('subject')) if request.args.get('paper_types'): query = query.filter(Exam.paper_types==request.args.get('paper_types')) if request.args.get('province_id'): query = query.filter(Exam.province_id==request.args.get('province_id')) if request.args.get('city_id'): query = query.filter(Exam.city_id==request.args.get('city_id')) if request.args.get('area_id'): query = query.filter(Exam.area_id==request.args.get('area_id')) if request.args.get('school_id'): query = query.filter(Exam.school_id==request.args.get('school_id')) if request.args.get('year'): query = query.filter(Exam.year==request.args.get('year')) if request.args.get('grade'): query = query.filter(Exam.grade==request.args.get('grade')) res = pagination(query) return res
def list_all_exams(): ''' 获取所有试卷 ''' query = Exam.query.filter(Exam.state != EXAM_STATUS['已删除']).\ order_by(Exam.order.desc()).\ order_by(Exam.created_at.desc()) if request.args.get('name'): query = query.filter(Exam.name.like('%{}%'.format(request.args.get('name')))) if request.args.get('subject'): query = query.filter(Exam.subject==request.args.get('subject')) if request.args.get('paper_types'): query = query.filter(Exam.paper_types==request.args.get('paper_types')) if request.args.get('province_id'): query = query.filter(Exam.province_id==request.args.get('province_id')) if request.args.get('city_id'): query = query.filter(Exam.city_id==request.args.get('city_id')) if request.args.get('area_id'): query = query.filter(Exam.area_id==request.args.get('area_id')) if request.args.get('school_id'): query = query.filter(Exam.school_id==request.args.get('school_id')) if request.args.get('year'): query = query.filter(Exam.year==request.args.get('year')) if request.args.get('grade'): query = query.filter(Exam.grade==request.args.get('grade')) if request.args.get('state'): query = query.filter(Exam.state==request.args.get('state')) res = pagination(query) return res
def get_fast(): exam_query = Exam.query.filter(Exam.state == EXAM_STATUS['未审核'], Exam.is_fast==1).\ order_by(Exam.order.desc()).\ order_by(Exam.created_at.desc()) if request.args.get('name'): exam_query = exam_query.filter( Exam.name.like('%{}%'.format(request.args.get('name')))) if request.args.get('subject'): exam_query = exam_query.filter( Exam.subject == request.args.get('subject')) if request.args.get('paper_types'): exam_query = exam_query.filter( Exam.paper_types == request.args.get('paper_types')) if request.args.get('province_id'): exam_query = exam_query.filter( Exam.province_id == request.args.get('province_id')) if request.args.get('city_id'): exam_query = exam_query.filter( Exam.city_id == request.args.get('city_id')) if request.args.get('area_id'): exam_query = exam_query.filter( Exam.area_id == request.args.get('area_id')) if request.args.get('school_id'): exam_query = exam_query.filter( Exam.school_id == request.args.get('school_id')) if request.args.get('year'): exam_query = exam_query.filter(Exam.year == request.args.get('year')) if request.args.get('grade'): exam_query = exam_query.filter(Exam.grade == request.args.get('grade')) res = pagination(exam_query) items = res.get('items', []) items = School.bind_auto(items, 'name') res['items'] = items return render_api(res)
def get(self): args = self.parser.parse_args() start_idx, end_idx = pagination(args["page"], args["offset"]) if args["title"]: post_list = Article.query.filter( Article.title.like('%' + args["title"] + '%')).all() else: post_list = Article.query.all() data = [marshal(item, ArticleListSerializer) for item in post_list][start_idx:end_idx] return {"data": data, "total": len(post_list)}, 200
def get_quest_by_state(state): query = Question.query.filter_by(state=state).\ order_by(Question.order.desc()).\ order_by(Question.created_at.desc()) res = pagination(query) items = res.get('items', []) items = Exam.bind_auto( items, ['name', 'year', 'school_id', 'section', 'subject', 'grade']) items = School.bind_auto(items, 'name', 'exam_school_id') res['items'] = items return res
def get_history(self): start_date = self.exam_date - datetime.timedelta(days=5) end_date = self.exam_date + datetime.timedelta(days=5) query = Exam.query.filter_by(subject=self.subject, year=self.year, is_fast=0, section=self.section, school_id=self.school_id, grade=self.grade).\ filter(Exam.id!=self.id).\ filter(Exam.exam_date >= start_date).\ filter(Exam.exam_date <= end_date).\ order_by(Exam.exam_date.desc()) res = pagination(query) return res
def list_quest_review_log(): query = Preprocess.query.\ filter_by(operator_id=g.user.id).\ order_by(Preprocess.created_at.desc()).\ join(Exam, Exam.id==Preprocess.exam_id) if request.args.get('name'): query = query.filter( Exam.name.like('%{}%'.format(request.args.get('name')))) if request.args.get('subject'): query = query.filter(Exam.subject == request.args.get('subject')) if request.args.get('paper_types'): query = query.filter( Exam.paper_types == request.args.get('paper_types')) if request.args.get('province_id'): query = query.filter( Exam.province_id == request.args.get('province_id')) if request.args.get('city_id'): query = query.filter(Exam.city_id == request.args.get('city_id')) if request.args.get('area_id'): query = query.filter(Exam.area_id == request.args.get('area_id')) if request.args.get('school_id'): query = query.filter(Exam.school_id == request.args.get('school_id')) if request.args.get('year'): query = query.filter(Exam.year == request.args.get('year')) if request.args.get('grade'): query = query.filter(Exam.grade == request.args.get('grade')) res = pagination(query) items = res.get('items', []) items = Exam.bind_auto(items, [ 'name', 'section', 'school_id', 'subject', 'grade', 'paper_types', 'province_id', 'city_id', 'area_id' ]) items = School.bind_auto(items, 'name', 'exam_school_id', 'id', 'school') items = Region.bind_auto(items, 'name', 'exam_province_id', 'id', 'province') items = Region.bind_auto(items, 'name', 'exam_city_id', 'id', 'city') items = Region.bind_auto(items, 'name', 'exam_area_id', 'id', 'area') res['items'] = items return render_api(res)
def get_deal_list(deal_obj): query = db.session.query(distinct(deal_obj.exam_id)).\ filter_by(operator_id=g.user.id) exam_ids = query.all() exam_ids = [id[0] for id in exam_ids] exam_query = Exam.query.filter(Exam.id.in_(exam_ids)).order_by(Exam.created_at.desc()) if request.args.get('name'): exam_query = exam_query.filter(Exam.name.like('%{}%'.format(request.args.get('name')))) if request.args.get('subject'): exam_query = exam_query.filter(Exam.subject==request.args.get('subject')) if request.args.get('paper_types'): exam_query = exam_query.filter(Exam.paper_types==request.args.get('paper_types')) if request.args.get('province_id'): exam_query = exam_query.filter(Exam.province_id==request.args.get('province_id')) if request.args.get('city_id'): exam_query = exam_query.filter(Exam.city_id==request.args.get('city_id')) if request.args.get('area_id'): exam_query = exam_query.filter(Exam.area_id==request.args.get('area_id')) if request.args.get('school_id'): exam_query = exam_query.filter(Exam.school_id==request.args.get('school_id')) if request.args.get('year'): exam_query = exam_query.filter(Exam.year==request.args.get('year')) if request.args.get('grade'): exam_query = exam_query.filter(Exam.grade==request.args.get('grade')) exams = pagination(exam_query) items = [] for item in exams['items']: questions = deal_obj.query.\ filter_by(operator_id=g.user.id).\ filter_by(exam_id=item['id']).\ order_by(deal_obj.quest_no.asc()).\ all() questions = [q.get_question_dtl() for q in questions] item['open'] = False item['questions'] = questions items.append(item) exams['items'] = School.bind_auto(items, 'name') return exams
def user_message(): data = pagination(g.user.messages) message_ids = [str(item['id']) for item in data['items']] Message.set_is_read(message_ids) return render_api(data)
def user_score(): data = pagination(g.user.scores) return render_api(data)
def paginate(self, to_dict=True): return pagination(self.query, None, to_dict)