Exemplo n.º 1
0
def exam_add_member(id,page=1,values=''):
    form = ExamStudentSearchForm()
    apply_num = ExamService.get_apply_num_by_id(id)

    if request.method == 'GET':
        values_json = {}
        if values != '':
            values_json = json.loads(base64.b64decode(values))
        pagination = UserService.search_userinfo(values_json,page)
        return render_template('web/exam_manage/exam_add_member.html',
                               id = id,
                               values = values,
                               form = form,
                               pagination = pagination,
                               user_list = pagination.items,
                               apply_num = apply_num,
                               level = Config.USER_LEVEL,
                               status = Config.STATUS,
                               active = Config.ADMIN_PAGE_ACTIVE['exam'])

    if form.validate_on_submit():
        if form.submit.data:
            values = base64.b64encode(json.dumps(form.to_dict()))
            return redirect(url_for('web.exam_add_member', id=id, page=1, values=values))

        elif form.submit_add.data:
            user_filter_list = UserService.search_userinfo_nopage(form.to_dict())                                                 #按条件批量获取用户id,并添加
            ExamService.add_exam_member_by_list(id,user_filter_list)
            return redirect(url_for('web.exam_add_member', id=id, page=page))
    else :
        return redirect(url_for('web.exam_add_member',id=id,page=page))
Exemplo n.º 2
0
def exam_member(id):
    form = ExamStudentSearchForm()
    apply_num = ExamService.get_apply_num_by_id(id)
    member_list = []
    for student in apply_num:
        member_list.append(UserService.get_userinfo_by_id(student))

    if request.method == 'GET':
        return render_template('admin/exam/exam_member.html',
                               id = id,
                               form = form,
                               member_list = member_list,
                               status=Config.STATUS,
                               active=Config.ADMIN_PAGE_ACTIVE['exam'])
    #对当前页面中用户进行筛选
    filter = []
    if form.validate_on_submit():

        if form.username.data:
            username = re.compile('.*'+form.username.data+'.*')
        if form.nickname.data:
            nickname = re.compile('.*'+form.nickname.data+'.*')
        if form.college.data:
            college = re.compile('.*'+form.college.data+'.*')
        if form.major.data:
            major = re.compile('.*'+form.major.data+'.*')
        for item in member_list:
            if username and username.search(item.user_name):
                filter.append(item)
                continue
            if nickname and nickname.search(item.nick_name):
                filter.append(item)
                continue
            if college and college.search(item.college_name):
                filter.append(item)
                continue
            if major and major.search(item.major_name):
                filter.append(item)
                continue
            if item.grade == form.grade.data or item.classnum == form.classnum.data:
                filter.append(item)
                continue

    return render_template('admin/exam/exam_member.html',
                           id=id,
                           form=form,
                           member_list=filter,
                           active=Config.ADMIN_PAGE_ACTIVE['exam'])