Ejemplo n.º 1
0
def Submissions_My(contest_id):
    try:
        page = int(request.args['page'])
    except:
        page = 1

    if not modules.Is_Loggedin():
        flash(r'请先登录', 'error')
        return modules.Page_Back()

    contest = db.Read_Contest(contest_id)
    if contest == None:
        flash(r'不存在的比赛', 'error')
        return modules.Page_Back()

    limitations = request.args.to_dict()
    limitations['contest_id'] = contest_id
    limitations['username'] = modules.Current_User()
    submissions = db.Read_Submissions(limitations)
    status_show, total_page = modules.Page_Split(submissions, page,
                                                 status_per_page,
                                                 lambda status: True)
    return render_template('status.html',
                           statuslist=status_show,
                           total_page=total_page,
                           current_page=page,
                           contest=contest,
                           contest_id=contest_id,
                           my=True)
Ejemplo n.º 2
0
def Submit(problemid,req,contest_id=0):
	if not modules.Is_Loggedin():
		flash('请先登录','error')
		return modules.Page_Back()

	code = req['code']
	if len(code) < 10:
		flash('这么短真的没问题?','error')
		return modules.Page_Back()

	username = request.cookies['username']
	last_submit_time = modules.Get_Session('last_submit_time',username)
	now_time = datetime.datetime.now()

	if last_submit_time != None:
		seconds = (now_time-last_submit_time).seconds
		if seconds < submit_delay_time:
			flash('请在 %ss 后提交'%(submit_delay_time-seconds),'error')
			return modules.Page_Back()
	modules.Set_Session('last_submit_time',username,now_time)

	maxid_result = db.Fetchone("SELECT MAX(id) FROM records;")[0]
	runid = 1 if maxid_result == None else int(maxid_result) + 1
	nowtime = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
	db.Execute("INSERT INTO records VALUES(%s,%s,%s,%s,0,0,'','{\"subtasks\":[]}',0,0,'',%s,%s,%s);",(runid,problemid,code,'cpp',username,contest_id,nowtime))

	r=redis.Redis(host='localhost',port=6379,decode_responses=True)
	r.rpush('intoj-waiting',str(runid))

	return redirect('/record/%d'%runid)
Ejemplo n.º 3
0
def Run():
    page = int(request.args['page']) if 'page' in request.args else 1

    problemlist = db.Read_Problemlist()

    can_view_hidden = modules.Current_User_Privilege(2)
    problem_show, total_page = modules.Page_Split(
        problemlist, page, problem_per_page,
        lambda problem: problem[9] or can_view_hidden)

    submitted_status = {}
    if modules.Is_Loggedin():

        def Better(new, before):
            if new[4] != before[4]: return new[4] > before[4]
            if new[5] != before[5]: return new[5] > before[5]
            if new[8] != before[8]: return new[8] < before[8]
            if new[9] != before[9]: return new[9] < before[9]
            if new[0] != before[0]: return new[0] > before[0]
            return False

        submissions = db.Read_Submissions(
            {'username': request.cookies['username']}, 'id ASC')
        for submission in submissions:
            problem_id = submission[1]
            if problem_id not in submitted_status or Better(
                    submission, submitted_status[problem_id]):
                submitted_status[problem_id] = submission

    return render_template('problemlist.html',
                           problemlist=problem_show,
                           submitted_status=submitted_status,
                           current_page=page,
                           total_page=total_page)
Ejemplo n.º 4
0
def Send_Zisheng():
    if not modules.Is_Loggedin():
        flash('请先登录', 'error')
        return False
    if not config.config['site']['zisheng']['enable']:
        flash('管理员已关闭「吱声」', 'error')
        return False

    message = request.form['message']
    max_length = config.config['site']['zisheng']['max_length']
    if len(message) > max_length:
        flash('超过最长长度: %d' % max_length, 'error')
        return False

    username = request.cookies['username']
    last_zisheng_time = modules.Get_Session('last_zisheng_time', username)
    now_time = datetime.datetime.now()
    if last_zisheng_time != None:
        seconds = (now_time - last_zisheng_time).seconds
        if seconds < zisheng_delay_time:
            flash('请在 %ss 后提交' % (zisheng_delay_time - seconds), 'error')
            return False
    modules.Set_Session('last_zisheng_time', username, now_time)

    nowtime = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
    db.Execute("INSERT INTO zisheng VALUES(NULL,%s,%s,%s);",
               (username, request.form['message'], nowtime))

    flash('发送成功', 'ok')
    return True
Ejemplo n.º 5
0
def Run(contest_id,problem_id):
	if not modules.Is_Loggedin():
		flash('请先登录','error')
		return modules.Page_Back()

	is_exist,ret = Is_Exist(contest_id,problem_id)
	if not is_exist: return ret

	if request.method == 'GET':
		return render_template('contest_problem.html',problem=ret[0],contest=ret[1])
	else:
		return Submit(contest_id,problem_id,request.form)