def get_dtl(self): result = super(Exam, self).to_dict() result = Region.bind_auto(result, 'name', 'city_id', 'id', 'city') result = Region.bind_auto(result, 'name', 'province_id', 'id', 'province') result = Region.bind_auto(result, 'name', 'area_id', 'id', 'area') result = School.bind_auto(result, 'name', 'school_id', 'id', 'school') return result
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_exam(id): result = Exam.query.get(int(id)) if result is not None: result = result.to_dict() else: return None result = Region.bind_auto(result, 'name', 'city_id', 'id', 'city') result = Region.bind_auto(result, 'name', 'province_id', 'id', 'province') result = Region.bind_auto(result, 'name', 'area_id', 'id', 'area') result = School.bind_auto(result, 'name', 'school_id', 'id', 'school') return result
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