Example #1
0
def contest_edit(id):
    contest = Contest.get_by_id(id)
    contest_form = ContestForm()
    contest_form.department.data = current_user.department
    if request.method == 'GET':
        contest_form.name_cn.data = contest.name_cn
        contest_form.name_en.data = contest.name_en
        contest_form.level.data = contest.level
        contest_form.type.data = contest.type
        contest_form.department.data = contest.department
        contest.site = contest_form.site.data
        contest_form.organizer.data = contest.organizer
        contest_form.co_organizer.data = contest.co_organizer
        if contest.series:
            contest_form.series_id.data = contest.series.id
        contest_form.year.data = contest.year
        contest_form.date_range.data = [contest.start_date.strftime('%Y/%m/%d'),
                                        contest.end_date.strftime('%Y/%m/%d')]

    if request.method == 'POST' and contest_form.validate():
        ret = Contest.update_contest(contest, contest_form, request)
        if ret == 'OK':
            return redirect(url_for('admin.contest'))
        elif ret == 'FAIL':
            flash(u'提交失败')
        else:
            flash(ret)
        print ret
    current_app.logger.error(contest_form.errors)
    return render_template('admin/contest_form.html',
                           title = u'修改竞赛',
                           action = url_for('admin.contest_edit', id=id),
                           contest_form = contest_form)
Example #2
0
File: views.py Project: TSS2/test
def contest_del():
    contest_id = request.form.get('contest_id', -1, type=int)
    if contest_id != -1:
        contest = Contest.get_by_id(contest_id)
        ret = Contest.delete_contest(contest)
    else:
        ret = u'删除失败'
    return jsonify(ret = ret)
Example #3
0
def contest_del():
    contest_id = request.form.get('contest_id', -1, type=int)
    if contest_id != -1:
        contest = Contest.get_by_id(contest_id)
        ret = Contest.delete_contest(contest)
    else:
        ret = u'删除失败'

    return jsonify(ret=ret)
Example #4
0
def contest_see(id):
    contest = Contest.get_by_id(id)
    contests = Contest.ResultList()
    contestResult = contests[0:]
    if request.method == 'POST':
        result = request.form.get('result', 0, type=int)
        current_app.logger.info(result)
        contest.result = contests[result - 1].name
        contest.save()
    return render_template('admin/contest_see.html',
                           title=u'竞赛查看',
                           contest=contest,
                           contestResult=contestResult)
Example #5
0
File: views.py Project: TSS2/a
def contest_plan_config_print():
    from datetime import date
    year_now = date.today().year
    cur_year = request.args.get('year', year_now, type=int) #获取连接里面的参数的值。year的值
    year_select = Contest.get_year()
    # year_select = [year for year in range(cur_year - 2, cur_year + 1)]
    department = current_user.department if current_user.department != u'教务处' else None
    contest_list = Contest.get_list_pageable(page=-1, department=department)
    return render_template('admin/contest_plan_config_print.html',
                           title = u'打印竞赛计划表',
                           department = department,
                           contest_list = contest_list,
                           year_select = year_select,
                           cur_year =cur_year,
                           int = int)
Example #6
0
File: views.py Project: TSS2/test
def pre_award():
    page = request.args.get('page', 1, type=int)
    filter_pass = request.args.get('filter_pass', 0, type=int)
    per_page = current_app.config['ADMIN_CONTEST_PER_PAGE']
    department = current_user.department if current_user.department != u'教务处' else None
    if page == -1:
        page = ((Contest.get_count(filter_pass, department) - 1) // per_page) + 1
    pagination = Contest.get_list_pageable(page, per_page, filter_pass,
                                           department)
    contest_list = pagination.items
    return render_template('admin/pre_award.html',
                           title = u'竞赛管理',
                           contest_list = contest_list,
                           pagination = pagination,
                           filter_pass = filter_pass)
Example #7
0
def contest_check(id):
    contest = Contest.get_by_id(id)
    contests = Contest.ResultList()
    contestResult = ContestResult.get_all()
    if request.method == 'POST':
        result = request.form.get('result', 0, type=int)
        current_app.logger.info(result)
        contest.result = contests[result - 1].name
        if contest.apply == u'0':
            contest.apply = 1
        contest.save()
    return render_template('admin/contest_check.html',
                           title=u'审核竞赛',
                           contest=contest,
                           contestResult=contestResult)
Example #8
0
File: views.py Project: TSS2/test
def awards_edit(id, awards_id):
    contest = Contest.get_by_id(id)
    awards = Awards.get_by_id(awards_id)
    exist_resources = awards.resources
    awards_form = AwardsForm()
    if request.method == 'GET':
        awards_form.honor.data = awards.honor
        awards_form.level.data = awards.level
        awards_form.title.data = awards.title
        awards_form.type.data = awards.type
        if awards.teachers:
            teacher = awards.teachers[0]
            awards_form.teachers.data = teacher.name
        awards_form.students.data = [s.stu_no for s in awards.students]
    if request.method == 'POST' and awards_form.validate():
        ret = Awards.update_awards(awards, awards_form, request.files)
        if ret == 'OK':
            return redirect(url_for('admin.awards', id=contest.id))
        elif ret == 'FAIL':
            flash(u'提交失败')
        else:
            flash(ret)
    return render_template('admin/awards_form.html',
                           title = u'奖项修改',
                           contest = contest,
                           awards_form = awards_form,
                           exist_resources = exist_resources)
Example #9
0
def awards_edit(id, awards_id):
    contest = Contest.get_by_id(id)
    awards = Awards.get_by_id(awards_id)
    exist_resources = awards.resources
    awards_form = AwardsForm()
    # if awards.apply == 3 or awards.apply == 5:
    #     cid = contest.contest_id
    #     Awards.set_all_apply_to_zero(cid)
    i = 1
    if request.method == 'GET':
        awards_form.honor.data = awards.honor
        awards_form.level.data = awards.level
        awards_form.title.data = awards.title
        awards_form.type.data = awards.type
        # if awards.teachers:
        #     teacher = awards.teachers[0]
        #     awards_form.teachers.data = teacher.name
        awards_form.teachers.data = [t.name for t in awards.teachers]
        awards_form.students.data = [s.stu_no for s in awards.students]
    if request.method == 'POST' and awards_form.validate():
        ret = Awards.update_awards(awards, awards_form, request.files)
        if ret == 'OK':
            return redirect(url_for('admin.awards', id=contest.id))
        elif ret == 'FAIL':
            flash(u'提交失败')
        else:
            flash(ret)
    return render_template('admin/awards_form.html',
                           title=u'奖项修改',
                           contest=contest,
                           awards_form=awards_form,
                           exist_resources=exist_resources,
                           awards=awards,
                           i=i)
Example #10
0
def awards_check(id, awards_id):
    contest = Contest.get_by_id(id)
    awards = Awards.get_by_id(awards_id)
    exist_resources = awards.resources
    awards_form = AwardsForm()
    department = current_user.department if current_user.department != u'教务处' else None
    if request.method == 'GET':
        awards_form.honor.data = awards.honor
        awards_form.level.data = awards.level
        awards_form.title.data = awards.title
        awards_form.type.data = awards.type
        if awards.teachers:
            teacher = awards.teachers[0]
            awards_form.teachers.data = teacher.name
        awards_form.students.data = [s.stu_no for s in awards.students]
    if request.method == 'POST' and awards_form.validate():
        ret = Awards.update_awards(awards, awards_form, request.files)
        if ret == 'OK':
            return redirect(url_for('admin.awards', id=contest.id))
        elif ret == 'FAIL':
            flash(u'提交失败')
        else:
            flash(ret)
    return render_template('admin/awards_form_check.html',
                           title=u'奖项查看',
                           contest=contest,
                           awards_form=awards_form,
                           awards=awards,
                           exist_resources=exist_resources,
                           department=department)
Example #11
0
def contest_plan_config_print():
    from datetime import date
    year_now = date.today().year
    cur_year = request.args.get('year', year_now,
                                type=int)  #获取连接里面的参数的值。year的值
    year_select = Contest.get_year()
    # year_select = [year for year in range(cur_year - 2, cur_year + 1)]
    department = current_user.department if current_user.department != u'教务处' else None
    contest_list = Contest.get_list_pageable(page=-1, department=department)
    return render_template('admin/contest_plan_config_print.html',
                           title=u'打印竞赛计划表',
                           department=department,
                           contest_list=contest_list,
                           year_select=year_select,
                           cur_year=cur_year,
                           int=int)
Example #12
0
def pre_award():
    page = request.args.get('page', 1, type=int)
    filter_pass = request.args.get('filter_pass', 0, type=int)
    per_page = current_app.config['ADMIN_CONTEST_PER_PAGE']
    department = current_user.department if current_user.department != u'教务处' else None
    if page == -1:
        page = (
            (Contest.get_count(filter_pass, department) - 1) // per_page) + 1
    pagination = Contest.get_list_pageable(page, per_page, filter_pass,
                                           department)
    contest_list = pagination.items
    return render_template('admin/pre_award.html',
                           title=u'竞赛管理',
                           contest_list=contest_list,
                           pagination=pagination,
                           filter_pass=filter_pass,
                           department=department)
Example #13
0
def contest_edit(id):
    contest = Contest.get_by_id(id)
    contest_form = ContestForm()
    contest_form.department.data = current_user.department
    if request.method == 'GET':
        contest_form.name_cn.data = contest.name_cn
        contest_form.name_en.data = contest.name_en
        #contest_form.level_id.data = contest.level
        contest_form.type.data = contest.type
        contest_form.department.data = contest.department
        contest_form.site.data = contest.site
        contest_form.organizer.data = contest.organizer
        contest_form.co_organizer.data = contest.co_organizer
        contest_form.place.data = contest.place
        if contest.series:
            contest_form.series_id.data = contest.series.id
        if contest.level_name:
            contest_form.level_id.data = contest.level.id
        # contest_form.year.data = contest.year
        contest_form.date_range.data = [
            contest.start_date.strftime('%Y/%m/%d'),
            contest.end_date.strftime('%Y/%m/%d')
        ]
        contest_form.budget.data = contest.budget
        contest_form.budget_text.data = contest.budget_text
        contest_form.student_num.data = contest.student_num
        contest_form.teacher_num.data = contest.teacher_num
        # contest_form.subject.data = contest.subject
    if request.method == 'POST' and contest_form.validate():
        ret = Contest.update_contest(contest, contest_form, request)
        if ret == 'OK':
            if contest.apply == u'3':
                contest.apply = 4
            contest.save()
            return redirect(url_for('admin.contest'))
        elif ret == 'FAIL':
            flash(u'提交失败')
        else:
            flash(ret)
        print ret
    current_app.logger.error(contest_form.errors)
    return render_template('admin/contest_form.html',
                           title=u'修改竞赛',
                           action=url_for('admin.contest_edit', id=id),
                           contest_form=contest_form)
Example #14
0
File: views.py Project: TSS2/test
def contest_plan_print():
    year = request.args.get('year', 0, type=int)
    department = current_user.department if current_user.department != u'教务处' else None
    contest_list = Contest.get_list_pageable(page=-1, department=department, year=year)
    return render_template('print/contest_plan.html',
                           contest_list = contest_list,
                           department = department.replace(u'学院', ''),
                           year = year,
                           len = len)
Example #15
0
def post_contest():
    json_data = request.json
    c = Contest()
    c.name = json_data["name"]
    c.body = json_data["body"]
    c.num_questions = json_data["num_questions"]
    c.answers = json_data["answers"]
    c.active = json_data["active"]
    db.session.add(c)
    db.session.commit()
    return c.serialize()
Example #16
0
File: views.py Project: TSS2/a
def awards_check_after_pass(id, awards_id):
    contest = Contest.get_by_id(id)
    awards = Awards.get_by_id(awards_id)
    exist_resources = awards.resources
    return render_template('admin/awards_see.html',
                           title = u'奖项查看1',
                           contest = contest,
                           awards = awards,
                           exist_resources = exist_resources,
                           )
Example #17
0
    def test_contest_add_new(self):
        '''
            test to insert into a new contest to database
        :return: None
        '''

        contest = Contest()
        db.session.add(contest)
        db.session.commit()
        self.assertTrue(Contest.query.count() == 1)
Example #18
0
def contest_plan_print():
    year = request.args.get('year', 0, type=int)
    department = current_user.department if current_user.department != u'教务处' else None
    contest_list = Contest.get_list_pageable(page=-1,
                                             department=department,
                                             year=year)
    return render_template('print/contest_plan.html',
                           contest_list=contest_list,
                           department=department.replace(u'学院', ''),
                           year=year,
                           len=len)
Example #19
0
def awards_check_after_pass(id, awards_id):
    contest = Contest.get_by_id(id)
    awards = Awards.get_by_id(awards_id)
    exist_resources = awards.resources
    return render_template(
        'admin/awards_see.html',
        title=u'奖项查看1',
        contest=contest,
        awards=awards,
        exist_resources=exist_resources,
    )
Example #20
0
File: views.py Project: TSS2/test
def contest_check(id):
    contest = Contest.get_by_id(id)
    contestResult = Contest.ContestResult[1:]
    if request.method == 'POST':
        result = request.form.get('result', 0, type=int)
        contest.result = Contest.ContestResult[result]
        contest.save()
    return render_template('admin/contest_check.html',
                           title = u'审核竞赛',
                           contest = contest,
                           contestResult = contestResult)
Example #21
0
File: views.py Project: TSS2/a
def contest_see(id):
    contest = Contest.get_by_id(id)
    contests = Contest.ResultList()
    contestResult = contests[0:]
    if request.method == 'POST':
        result = request.form.get('result', 0, type=int)
        current_app.logger.info(result)
        contest.result = contests[result-1].name
        contest.save()
    return render_template('admin/contest_see.html',
                           title = u'竞赛查看',
                           contest = contest,
                           contestResult = contestResult)
Example #22
0
File: views.py Project: TSS2/a
def contest_apply_refuse(id):
    contest = Contest.get_by_id(id)
    if contest.apply == u'2':
        contest.apply = 1
    elif contest.apply == u'4':
        contest.apply = 3
    contest.save()
    page = request.args.get('page', 1, type=int)
    filter_pass = request.args.get('filter_pass', 0, type=int)
    per_page = current_app.config['ADMIN_CONTEST_PER_PAGE']
    department = current_user.department if current_user.department != u'教务处' else None
    if page == -1:
        page = ((Contest.get_count(filter_pass, department) - 1) // per_page) + 1
    pagination = Contest.get_list_pageable(page, per_page, filter_pass,
                                           department)
    contest_list = pagination.items
    return render_template('admin/contest.html',
                           title = u'竞赛管理',
                           contest_list = contest_list,
                           pagination = pagination,
                           filter_pass = filter_pass,
                           department = department)
Example #23
0
def contest_apply_refuse(id):
    contest = Contest.get_by_id(id)
    if contest.apply == u'2':
        contest.apply = 1
    elif contest.apply == u'4':
        contest.apply = 3
    contest.save()
    page = request.args.get('page', 1, type=int)
    filter_pass = request.args.get('filter_pass', 0, type=int)
    per_page = current_app.config['ADMIN_CONTEST_PER_PAGE']
    department = current_user.department if current_user.department != u'教务处' else None
    if page == -1:
        page = (
            (Contest.get_count(filter_pass, department) - 1) // per_page) + 1
    pagination = Contest.get_list_pageable(page, per_page, filter_pass,
                                           department)
    contest_list = pagination.items
    return render_template('admin/contest.html',
                           title=u'竞赛管理',
                           contest_list=contest_list,
                           pagination=pagination,
                           filter_pass=filter_pass,
                           department=department)
Example #24
0
File: views.py Project: TSS2/a
def contest_check(id):
    contest = Contest.get_by_id(id)
    contests = Contest.ResultList()
    contestResult = ContestResult.get_all()
    if request.method == 'POST':
        result = request.form.get('result', 0, type=int)
        current_app.logger.info(result)
        contest.result = contests[result-1].name
        if contest.apply == u'0':
            contest.apply = 1
        contest.save()
    return render_template('admin/contest_check.html',
                           title = u'审核竞赛',
                           contest = contest,
                           contestResult = contestResult)
Example #25
0
File: views.py Project: TSS2/test
def awards_add(id):
    contest = Contest.get_by_id(id)
    awards_form = AwardsForm()
    if request.method == 'POST' and awards_form.validate():
        ret = Awards.create_awards(awards_form, contest, request.files)
        if ret == 'OK':
            return redirect(url_for('admin.awards', id=contest.id))
        elif ret == 'FAIL':
            flash(u'提交失败')
        else:
            flash(ret)
    return render_template('admin/awards_form.html',
                           title = u'奖项录入',
                           contest = contest,
                           awards_form = awards_form)
Example #26
0
File: views.py Project: TSS2/test
def awards(id):
    contest = Contest.get_by_id(id)
    page = request.args.get('page', 1, type=int)
    per_page = current_app.config['ADMIN_AWARDS_PER_PAGE']
    if page == -1:
        page = ((Awards.get_count(contest_id=contest.contest_id) - 1) // per_page) + 1
    pagination = Awards.get_list_pageable(page, per_page,
                                          contest_id=contest.contest_id)
    awards_list = pagination.items
    return render_template('admin/awards.html',
                           title = u'奖项管理',
                           contest = contest,
                           awards_list = awards_list,
                           pagination = pagination,
                           process = Awards.AwardsProcess)
Example #27
0
def contest_add():
    contest_form = ContestForm()
    contest_form.department.data = current_user.department
    if request.method == 'POST' and contest_form.validate():
        ret = Contest.create_contest(contest_form, request)
        if ret == 'OK':
            return redirect(url_for('admin.contest'))
        elif ret == 'FAIL':
            flash(u'提交失败')
        else:
            flash(ret)
    current_app.logger.error(contest_form.errors)
    return render_template('admin/contest_form.html',
                           title=u'添加竞赛',
                           action=url_for('admin.contest_add'),
                           contest_form=contest_form)
Example #28
0
File: views.py Project: TSS2/test
def contest_add():
    contest_form = ContestForm()
    contest_form.department.data = current_user.department
    if request.method == 'POST' and contest_form.validate():
        ret = Contest.create_contest(contest_form, request)
        if ret == 'OK':
            return redirect(url_for('admin.contest'))
        elif ret == 'FAIL':
            flash(u'提交失败')
        else:
            flash(ret)
    current_app.logger.error(contest_form.errors)
    return render_template('admin/contest_form.html',
                           title = u'添加竞赛',
                           action = url_for('admin.contest_add'),
                           contest_form = contest_form)
Example #29
0
    def test_contest_user(self):
        '''
            test for add user to contest is good
        :return: None
        '''

        contest = Contest()
        db.session.add(contest)
        db.session.commit()
        user = User()
        db.session.add(user)
        db.session.commit()
        contest_user = ContestUsers(contest=contest, user=user)
        db.session.add(contest_user)
        db.session.commit()
        self.assertTrue(contest.users.first().user.id == user.id)
        db.session.delete(contest_user)
        db.session.commit()
        self.assertTrue(contest.users.count() == 0)
Example #30
0
    def test_contest_problem(self):
        '''
            test for add problem to contest is good
        :return: None
        '''

        contest = Contest()
        db.session.add(contest)
        db.session.commit()
        problem = Problem()
        db.session.add(problem)
        db.session.commit()
        contest_problem = ContestProblem(contest=contest, problem=problem)
        db.session.add(contest_problem)
        db.session.commit()
        self.assertTrue(contest.problems.first().problem.id == problem.id)
        db.session.delete(contest_problem)
        db.session.commit()
        self.assertTrue(contest.problems.count() == 0)
Example #31
0
def statistics_form():
    all_contest = Contest.get_alls()
    j = 0
    department = []
    for next_contest in all_contest:
        department.append(all_contest[j].department)
        j = j + 1
    counter = Counter(department)
    all_awards = Awards.get_all()
    i = 0
    level = []
    for next_awards in all_awards:
        level.append(all_awards[i].level)
        i = i + 1
    levels = Counter(level)
    return render_template('admin/statisticsform.html',
                           title=u'统计',
                           counter=counter,
                           level=levels)
Example #32
0
def awards(id):
    contest = Contest.get_by_id(id)
    page = request.args.get('page', 1, type=int)
    per_page = current_app.config['ADMIN_AWARDS_PER_PAGE']
    department = current_user.department if current_user.department != u'教务处' else None
    if page == -1:
        page = ((Awards.get_count(contest_id=contest.contest_id) - 1) //
                per_page) + 1
    pagination = Awards.get_list_pageable(page,
                                          per_page,
                                          contest_id=contest.contest_id)
    awards_list = pagination.items
    return render_template('admin/awards.html',
                           title=u'奖项管理',
                           contest=contest,
                           awards_list=awards_list,
                           pagination=pagination,
                           process=Awards.AwardsProcess,
                           department=department)
Example #33
0
File: views.py Project: TSS2/a
def statistics_form():
    all_contest = Contest.get_alls()
    j = 0
    department = []
    for next_contest in all_contest:
        department.append(all_contest[j].department)
        j = j + 1
    counter = Counter(department)
    all_awards = Awards.get_all()
    i = 0
    level = []
    for next_awards in all_awards:
        level.append(all_awards[i].level)
        i = i + 1
    levels = Counter(level)
    return render_template('admin/statisticsform.html',
                           title = u'统计',
                           counter = counter,
                           level = levels
                           )
Example #34
0
def awards_add(id):
    contest = Contest.get_by_id(id)
    awards_form = AwardsForm()
    i = 0
    awards_form.department.data = current_user.department
    # cid = contest.contest_id
    # Awards.set_new_apply(cid)
    request.values.get('StudentList')
    if request.method == 'POST' and awards_form.validate():
        ret = Awards.create_awards(awards_form, contest, request.files)
        if ret == 'OK':
            return redirect(url_for('admin.awards', id=contest.id))
        elif ret == 'FAIL':
            flash(u'提交失败')
        else:
            flash(ret)
    return render_template('admin/awards_form.html',
                           title=u'奖项录入',
                           contest=contest,
                           awards_form=awards_form,
                           i=i)
Example #35
0
File: views.py Project: TSS2/a
def awards_add(id):
    contest = Contest.get_by_id(id)
    awards_form = AwardsForm()
    i =0
    awards_form.department.data = current_user.department
    # cid = contest.contest_id
    # Awards.set_new_apply(cid)
    request.values.get('StudentList')
    if request.method == 'POST' and awards_form.validate():
        ret = Awards.create_awards(awards_form, contest, request.files)
        if ret == 'OK':
            return redirect(url_for('admin.awards', id=contest.id))
        elif ret == 'FAIL':
            flash(u'提交失败')
        else:
            flash(ret)
    # Student.remove_student()
    return render_template('admin/awards_form.html',
                           title = u'奖项录入',
                           contest = contest,
                           awards_form = awards_form,
                           i=i
                           )
Example #36
0
    def test_insert_topic(self):
        '''
            test to insert into a new topic and comment to database
        :return: None
        '''

        contest = Contest()
        db.session.add(contest)
        user = User(username='******')
        db.session.add(user)
        db.session.commit()
        topic = Topic()
        topic.contest_id = contest.id
        topic.author_username = user.username
        db.session.add(topic)
        db.session.commit()
        self.assertTrue(topic.contest.id == contest.id)
        comment = TopicComment()
        comment.topic_id = topic.id
        db.session.add(comment)
        db.session.commit()
        self.assertTrue(topic.comments.first().id == comment.id)
        db.session.delete(topic)
        db.session.commit()
        self.assertTrue(TopicComment.query.count() == 0)
        topic = Topic()
        topic.contest_id = contest.id
        topic.author_username = user.username
        db.session.add(topic)
        db.session.commit()
        comment = TopicComment()
        comment.topic_id = topic.id
        db.session.add(comment)
        db.session.commit()
        db.session.delete(contest)
        db.session.commit()
        self.assertTrue(Topic.query.count() == 0)
Example #37
0
def awards_refuse_check(id):
    contest = Contest.get_by_id(id)
    cid = contest.contest_id
    Awards.set_all_apply_refuse(cid)
    return redirect(url_for('admin.awards', id=id))
Example #38
0
def contest_print(id):
    contest = Contest.get_by_id(id)
    return render_template('print/contest.html', contest=contest)
Example #39
0
File: views.py Project: TSS2/test
def contest_print(id):
    contest = Contest.get_by_id(id)
    return render_template('print/contest.html',
                           contest = contest)
Example #40
0
File: views.py Project: TSS2/a
def awards_refuse_check(id):
    contest = Contest.get_by_id(id)
    cid = contest.contest_id
    Awards.set_all_apply_refuse(cid)
    return  redirect(url_for('admin.awards',id = id))