def exam_update(id): form = ExamUpdateForm() if request.method == 'GET': exam_info = ExamService.get_exam_detail_info(id) form.describe.data = exam_info.describe form.name.data = exam_info.name form.creater.data = exam_info.creater form.count.data = exam_info.count form.during_time.data = exam_info.during_time form.start_time.data = exam_info.start_time form.end_time.data = exam_info.end_time form.reg_start_time.data = exam_info.reg_start_time form.reg_end_time.data = exam_info.reg_end_time form.is_register.data = str(exam_info.is_register) form.is_hidden.data = str(exam_info.is_hidden) form.is_show_result.data = str(exam_info.is_show_result) return render_template('web/exam_manage/exam_update.html', id = id, form = form, active = Config.ADMIN_PAGE_ACTIVE['exam']) if form.validate_on_submit(): try: ExamService.update_exam(form,id) flash("Update exam success") return redirect(url_for('web.exam_update',id=id)) except: flash("Update exam failed") return redirect(url_for('web.exam_update', id=id))
def function(*args, **kwargs): failed = 'You do not have permission to enter' url = url_for('web.exam_list') path = request.path.split('/') id = path[-2] count = int(path[-1]) now_date = datetime.now() exam_page = ExamConditionService.get_user_exam_page( id, current_user.user_id, count) exam_end_time = exam_page['end_time'] #考试的设定信息 exam_info = ExamService.get_exam_detail_info(id) #已经考的场数 exam_count = ExamConditionService.get_user_exam_count( id, current_user.user_id) #中途加入的考试必须为最新的一场即下标为exam_count-1 if count != exam_count - 1: return render_template("web/failed.html", failed=failed, url=url) #验证考试时间 if now_date < exam_info.start_time or now_date > exam_info.end_time: return render_template("web/failed.html", failed=failed, url=url) #获取当前时间 now_time = time.time() # +5s 延迟,防止js强制结束考试时无法提交 if now_time > exam_end_time + 5: return render_template("web/failed.html", failed=failed, url=url) return f(*args, **kwargs)
def function(*args, **kwargs): failed = 'You do not have permission to enter' url = url_for('web.exam_list') path = request.path.split('/') id = path[-2] count = int(path[-1]) now_date = datetime.now() now_time = int(time.time()) #考试设定信息 exam_info = ExamService.get_exam_detail_info(id) #已经考的场数 exam_count = ExamConditionService.get_user_exam_count( id, current_user.user_id) # 如果考试不是无限次那么已经考试次数>=设定次数就不能参加考试 if exam_info.count != -1 and exam_count >= exam_info.count: return render_template("web/failed.html", failed=failed, url=url) #由于是新建考试,那么当前my_answer列表长度即新一场考试在列表中的下标,数值完全匹配才能够新建考试 #(0号下标依然成立) if count != exam_count: return render_template("web/failed.html", failed=failed, url=url) if count != 0: # 获得上一场考试的情况(用于验证上一场考试是否结束) exam_page = ExamConditionService.get_user_exam_page( id, current_user.user_id, count - 1) #如果要新建的考试不是第一场次考试, 那么检查上一场的考试 if exam_page['now_time'] < exam_page['end_time']: if now_time < exam_page['end_time']: return render_template("web/failed.html", failed=failed, url=url) #验证考试时间 if now_date < exam_info.start_time or now_date > exam_info.end_time: return render_template("web/failed.html", failed=failed, url=url) return f(*args, **kwargs)
def create_page(id): examAllInfo = ExamService.get_exam_detail_info(id) choice = [] blank = [] short_answer = [] problem_list = [] if examAllInfo.is_random == 1: problem_list = examAllInfo.problem_list elif examAllInfo.is_random == 0: problem_list = examAllInfo.problem_list_example for problem in problem_list: problem_detail = ProLibService.get_problem_detailed_info(problem) if problem_detail.type == Config.PROBLEM_TYPE['choice']: # 选项乱序 list = problem_detail.desc_other.split('#$') problem_detail.desc_other = random.sample(list, len(list)) choice.append(problem_detail) elif problem_detail.type == Config.PROBLEM_TYPE['blank']: blank.append(problem_detail) elif problem_detail.type == Config.PROBLEM_TYPE['short_answer']: short_answer.append(problem_detail) # 题目乱序 choice_r = random.sample(choice, examAllInfo.choice['num']) blank_r = random.sample(blank, examAllInfo.blank['num']) short_answer_r = random.sample(short_answer, examAllInfo.answer['num']) # 生成json exam_page = {} exam_page['name'] = examAllInfo.name exam_page['choice'] = [] exam_page['blank'] = [] exam_page['short_answer'] = [] exam_page['times'] = examAllInfo.during_time #记录时长 exam_page['now_time'] = int(time.time()) #当前时间(时间戳,在render前赋值保证精确) exam_page['end_time'] = exam_page['now_time'] + exam_page['times'] #结束时间(时间戳,在render前赋值保证精确) exam_page['choice_score'] = examAllInfo.choice['score'] exam_page['blank_score'] = examAllInfo.blank['score'] exam_page['short_answer_score'] = examAllInfo.answer['score'] #count为当前考试在my_answer列表中的下标值 exam_page['count'] = ExamConditionService.get_user_exam_count(id, current_user.user_id) ''' { 'choice':[ {'pid':'123', 'describe_main':'test1', 'describe_other':['a','b','c','d'], }, {'pid':'1234', 'describe_main':'test2', 'describe_other':['a','b','c','d','e'], } ], 'blank':[ {'pid':'1111', 'describe_main':'test3', 'describe_other':'', 'answer':'' }] 'short_answer':[], 'name':'Test', 'times':'120', 'now_time':'' 'end_time':'' 'choice_score':10, 'blank_score':0, 'short_answer_score':0 'count':0 } ''' for problem in choice_r: problem_dict = {'pid': problem.pid, 'desc_main': problem.desc_main, 'desc_other': problem.desc_other, 'answer': ''} exam_page['choice'].append(problem_dict) for problem in blank_r: problem_dict = {'pid': problem.pid, 'desc_main': problem.desc_main, 'desc_other': problem.desc_other, 'answer': ''} exam_page['blank'].append(problem_dict) for problem in short_answer_r: problem_dict = {'pid': problem.pid, 'desc_main': problem.desc_main, 'desc_other': problem.desc_other, 'answer': ''} exam_page['short_answer'].append(problem_dict) return exam_page
def exam_problem(id): form = ExamProblemNumForm() examinfo = ExamService.get_exam_detail_info(id) problem_list_exam = examinfo.problem_list #考试题库题目id列表 problem_list_example = examinfo.problem_list_example #考试样例试卷题目id列表 problem_condition_dict = ExamService.get_problem_condition_dict_byid(id) #考题情况字典 choice = [] blank = [] short_answer = [] choice_ex = [] blank_ex = [] short_answer_ex = [] # 考试题目列表仅仅有id,通过循环获取 # 题目相关信息,下一循环同理 # 区别在于题库和样例试卷的题目不同 for problem in problem_list_exam: problem_detail = ProLibService.get_problem_detailed_info(problem) problem_detail.belong_to_book = BookService.get_book_by_id(problem_detail.belong_to_book).book_name problem_detail.belong_to_unit = BookService.get_unit_by_id(problem_detail.belong_to_unit).unit_name problem_detail.belong_to_section = BookService.get_section_by_id(problem_detail.belong_to_section).section_name if problem_detail.type == Config.PROBLEM_TYPE['choice']: choice.append(problem_detail) elif problem_detail.type == Config.PROBLEM_TYPE['blank']: blank.append(problem_detail) elif problem_detail.type == Config.PROBLEM_TYPE['short_answer']: short_answer.append(problem_detail) for problem in problem_list_example: problem_detail = ProLibService.get_problem_detailed_info(problem) problem_detail.belong_to_book = BookService.get_book_by_id(problem_detail.belong_to_book).book_name problem_detail.belong_to_unit = BookService.get_unit_by_id(problem_detail.belong_to_unit).unit_name problem_detail.belong_to_section = BookService.get_section_by_id(problem_detail.belong_to_section).section_name if problem_detail.type == Config.PROBLEM_TYPE['choice']: choice_ex.append(problem_detail) elif problem_detail.type == Config.PROBLEM_TYPE['blank']: blank_ex.append(problem_detail) elif problem_detail.type == Config.PROBLEM_TYPE['short_answer']: short_answer_ex.append(problem_detail) problem_list_dict = dict((('choice',choice),('blank',blank),('short_answer',short_answer))) problem_list_example_dict = dict((('choice', choice_ex), ('blank', blank_ex), ('short_answer', short_answer_ex))) if request.method == 'GET': form.choice_num.choices = [(i, i) for i in range(len(choice) + 1)] form.blank_num.choices = [(i, i) for i in range(len(blank) + 1)] form.short_answer_num.choices = [(i, i) for i in range(len(short_answer) + 1)] form.choice_num.data = str(problem_condition_dict['choice']['num']) form.choice_score.data = str(problem_condition_dict['choice']['score']) form.blank_num.data = str(problem_condition_dict['blank']['num']) form.blank_score.data = str(problem_condition_dict['blank']['score']) form.short_answer_num.data = str(problem_condition_dict['short_answer']['num']) form.short_answer_score.data = str(problem_condition_dict['short_answer']['num']) form.is_random.data = str(problem_condition_dict['is_random']) return render_template('web/exam_manage/exam_problem.html', form = form, id = id, is_random = problem_condition_dict['is_random'], problem_num_dict = problem_condition_dict, problem_list_dict = problem_list_dict, problem_list_example = problem_list_example_dict, status=Config.STATUS, active=Config.ADMIN_PAGE_ACTIVE['exam']) if request.method == 'POST': ExamService.update_problem_number(form,id) return redirect(url_for('web.exam_problem',id=id))