Exemplo n.º 1
0
    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)
Exemplo n.º 2
0
def show_exam(id):
    if request.method == 'GET':
        user_info = {}
        if current_user.user_level > 1:
            condition = ExamConditionService.get_user_exam_condition_by_examid(
                id)
            for con in condition:
                user_info[con.sutdent_id] = UserService.get_userinfo_by_id(
                    con.sutdent_id)
            condition = zip(condition, range(1, len(condition) + 1))
            return render_template('web/exam/look_exam.html',
                                   condition=condition,
                                   user_info=user_info,
                                   current_user=current_user)

        elif current_user.user_level == 1:
            user_info_dict = {}
            condition_list = []
            condition = ExamConditionService.get_user_exam_condition_by_userid(
                id, current_user.user_id)
            user_info = UserService.get_userinfo_by_id(current_user.user_id)
            user_info_dict[condition.student_id] = user_info
            condition_list.append(condition)
            condition_list = zip(condition_list,
                                 range(1,
                                       len(condition_list) + 1))
            return render_template('web/exam/look_exam.html',
                                   condition=condition_list,
                                   user_info=user_info_dict,
                                   current_user=current_user)
Exemplo n.º 3
0
def save_page(id,count):

    try:
        answer_json = request.json
        print  answer_json
        # 在进入页面时loginfo列表添加了新的一项此时为对应下标应-1
        ExamConditionService.save_page(id,current_user.user_id,None,answer_json,count)
        return json.dumps({'key':'success'})
    except:
        return json.dumps({'key':'failed'})
Exemplo n.º 4
0
def examing(id,count):
    if request.method == 'GET':
        #记录登入信息,更新参考用户
        login_ip = request.remote_addr
        ExamConditionService.update_exam_condition_begin(id,current_user.user_id,login_ip)
        #生成考试页面存储到my_answer里
        page_dict = create_page(id)
        page_dict['now_time'] = int(time.time())
        page_dict['end_time'] = page_dict['now_time'] + page_dict['times'] * 60
        exam_page_json = json.dumps(page_dict)
        ExamConditionService.save_page(id, current_user.user_id, exam_page_json, None, count)
        return render_template('web/exam/exam.html',id=id)
Exemplo n.º 5
0
def add_exam_member_single(id,user_id,page=1,values=''):
    try:
        if UserService.get_userinfo_by_id(user_id).status:
            ExamService.add_exam_member_single(id,user_id)
            ExamConditionService.add_user_exam_condition(id, user_id)
            flash('success')
        else:
            flash('failed')
    except:
        flash('failed')

    if values == '':
        return redirect(url_for('web.exam_add_member', id=id, page=page))

    return redirect(url_for('web.exam_add_member',id=id,page=page,values=values))
Exemplo n.º 6
0
def get_page(id,count):

    page,answer = ExamConditionService.get_page(id,current_user.user_id,count)
    page = json.loads(page)
    page['now_time'] = int(time.time())
    page_dict = {'page':page,'answer':answer}
    page_json = json.dumps(page_dict)

    return page_json
Exemplo n.º 7
0
def exam_history(page=1):
    if request.method == 'GET':
        pagination = ExamService.get_user_exam_history(current_user, page)
        exam_count = ExamConditionService.get_user_exam_count_all(
            current_user.user_id)
        return render_template('web/exam/own_exam.html',
                               pagination=pagination,
                               exam_count=exam_count,
                               exam_list=pagination.items,
                               current_user=current_user)
Exemplo n.º 8
0
def exam_list(page=1):
    if request.method == 'GET':
        pagination = ExamService.get_user_exam_during(current_user, page)
        exam_count = ExamConditionService.get_user_exam_count_all(
            current_user.user_id)
        now_time = int(time.time())
        return render_template('web/exam/exam_list.html',
                               pagination=pagination,
                               exam_count=exam_count,
                               nowtime=now_time,
                               exam_list=pagination.items,
                               current_user=current_user)
Exemplo n.º 9
0
    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)
Exemplo n.º 10
0
def get_page_result(id,count):

    page,answer = ExamConditionService.get_page(id,current_user.user_id,count)
    page = json.loads(page)
    true_answer = {}
    for item in page['choice']+page['blank']+page['short_answer']:
        pid = item['pid']
        true_answer[pid]=ProLibService.get_problem_detailed_info(item['pid']).answer

    page['now_time'] = int(time.time())
    page_dict = {'page':page,'answer':answer,'true_answer':true_answer}
    print true_answer
    page_json = json.dumps(page_dict)

    return page_json
Exemplo n.º 11
0
def exam_finish(id,count):
    exam_answer = request.json
    ExamConditionService.save_page(id,current_user.user_id,None,exam_answer,count)
    print exam_answer
    logout_ip = request.remote_addr
    ExamConditionService.update_exam_condition(id,current_user.user_id,logout_ip,count)

    grade = 0
    problem_condition_dict = ExamService.get_problem_condition_dict_byid(id)

    for pid, answer in exam_answer['choice'].items():
        problem = ProLibService.get_problem_detailed_info(pid)
        if answer == problem.answer:
            grade += problem_condition_dict['choice']['score']

    ExamConditionService.update_user_exam_grade(id, current_user.user_id, grade, count)

    return json.dumps({'key':'success'})
Exemplo n.º 12
0
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
Exemplo n.º 13
0
def exam_continue(id,count):
    # 记录登入信息,更新参考用户
    login_ip = request.remote_addr
    ExamConditionService.update_exam_condition_begin(id, current_user.user_id, login_ip)

    return render_template('web/exam/exam.html',id=id,count=count)