def view_problem(problem_id, sub_id): problem = app.contest.problems.get(problem_id) phase = app.contest.get_current_phase() if not problem: abort(404) if request.method == 'POST': if problem_id not in phase.submit_problems: abort(404) if not is_logged_in(): return redirect(url_for('default.login', next=request.path)) team = get_team() if ( 'language' in request.form and ('source_file' in request.files or 'source_code' in request.form) and request.form['language'] in app.contest.languages): if 'source_file' in request.files: code = request.files['source_file'].read() try: code = code.decode('utf-8') except UnicodeDecodeError: code = text.bytes2unicode(code) if 'source_file' not in request.files or not code: code = request.form['source_code'] sub = Submission( team=team.name, problem=problem_id, language=request.form['language'], file=code, submitted=datetime.datetime.now() ) team.last_used_language = request.form['language'] app.db.session.add(sub) app.db.session.flush() app.db.session.add(SubmissionQueue(submission_id=sub.id)) app.db.session.commit() else: abort(400) return redirect(url_for('default.list_submissions')) if problem_id not in phase.visible_problems: abort(404) sub = None if sub_id is not None: team = get_team() sub = Submission.query.filter_by(id=sub_id).first() if not sub or sub.team != team.name: abort(404) return render_template('problem.html', problem=problem, sub=sub)
def view_submission(sub_id): sub = Submission.query.filter_by(id=sub_id).first() if not sub: abort(404) if request.method == 'POST': if 'verdict' in request.form and 'judge_response' in request.form: v = request.form['verdict'].split('+') if not (len(v) == len(set(v)) and set(v) <= set(verdict_explanation.keys())): abort(400) sub.verdict = request.form['verdict'] sub.judge_response = request.form['judge_response'] if sub.verdict == 'QU': qsub = SubmissionQueue.query.filter_by( submission_id=sub.id).first() if qsub: qsub.dequeued_at = None else: app.db.session.add(SubmissionQueue(sub.id)) app.db.session.commit() return redirect(url_for('judge.view_submission', sub_id=sub_id)) else: abort(400) return render_template('judge/submission.html', submission=sub)
def view_submission(sub_id): sub = Submission.query.filter_by(id=sub_id).first() if not sub: abort(404) if request.method == 'POST': if 'verdict' in request.form and 'judge_response' in request.form: v = request.form['verdict'].split('+') if not (len(v) == len(set(v)) and set(v) <= set(verdict_explanation.keys())): abort(400) sub.verdict = request.form['verdict'] sub.judge_response = request.form['judge_response'] if sub.verdict == 'QU': qsub = SubmissionQueue.query.filter_by(submission_id=sub.id).first() if qsub: qsub.dequeued_at = None else: app.db.session.add(SubmissionQueue(sub.id)) app.db.session.commit() return redirect(url_for('judge.view_submission', sub_id=sub_id)) else: abort(400) return render_template('judge/submission.html', submission=sub)
def register(): global contest if not app.contest.register or is_logged_in(): abort(404) team_name = '' error = [] if request.method == 'POST': # TODO: make sure 'team' and 'password' are in request.form team_name = request.form['team'] password = request.form['password'] confirm_password = request.form['confirm_password'] rx = '^[-_A-Za-z0-9 ]{3,20}$' if not re.match(rx, team_name): error.append('Team name is illegal (it must match %s).' % rx) if team_name in app.contest.teams: error.append('Team name is already taken.') rx = '^[-_A-Za-z0-9 ]{5,20}$' if not re.match(rx, password): error.append('Password is illegal (it must match %s).' % rx) if password != confirm_password: error.append('Password confirmation was incorrect.') if not error: _register_team(team_name, password) return redirect(url_for('default.login', register='True')) return render_template('register.html', team_name=team_name, error=error)
def login(): goto = request.args.get('next', url_for('judge.index')) judge_name = '' bad_login = False if judge_is_logged_in(): return redirect(goto) if request.method == 'POST': # TODO: make sure 'team' and 'password' are in request.form judge_name = request.form['judge'] password = request.form['password'] if judge_name in app.contest.judges and app.contest.judges[judge_name].password == password: session['judge'] = judge_name return redirect(goto) else: session.pop('judge', '') bad_login = True return render_template('judge/login.html', judge_name=judge_name, bad_login=bad_login)
def login(): goto = request.args.get('next', url_for('index')) registered = request.args.get('register', 'False') == 'True' team_name = '' bad_login = False if is_logged_in(): return redirect(goto) if request.method == 'POST': # TODO: make sure 'team' and 'password' are in request.form team_name = request.form['team'] password = request.form['password'] if team_name in app.contest.teams and app.contest.teams[team_name].password == password: session['team'] = team_name return redirect(goto) else: session.pop('team', '') bad_login = True return render_template('login.html', team_name=team_name, bad_login=bad_login, registered=registered)
def login(): goto = request.args.get('next', url_for('judge.index')) judge_name = '' bad_login = False if judge_is_logged_in(): return redirect(goto) if request.method == 'POST': # TODO: make sure 'team' and 'password' are in request.form judge_name = request.form['judge'] password = request.form['password'] if judge_name in app.contest.judges and app.contest.judges[ judge_name].password == password: session['judge'] = judge_name return redirect(goto) else: session.pop('judge', '') bad_login = True return render_template('judge/login.html', judge_name=judge_name, bad_login=bad_login)
def balloons(id): if id is not None: balloon = BalloonModel.query.filter_by(balloon_id=id).first() if balloon: balloon.delivered = True app.db.session.commit() return redirect(url_for('judge.balloons')) submissions = {sub.id: sub for sub in Submission.query.all()} dballoons = BalloonModel.query.all() balloons = [] for balloon in dballoons: sub = submissions[balloon.submission_id] team = app.contest.teams[sub.team] problem = app.contest.problems[sub.problem] balloons.append(Balloon(balloon.balloon_id, sub, team, problem, balloon.delivered)) return render_template('judge/balloons.html', balloons=sorted(balloons, key=lambda balloon: balloon.submission.submitted) )
def balloons(id): if id is not None: balloon = BalloonModel.query.filter_by(balloon_id=id).first() if balloon: balloon.delivered = True app.db.session.commit() return redirect(url_for('judge.balloons')) submissions = {sub.id: sub for sub in Submission.query.all()} dballoons = BalloonModel.query.all() balloons = [] for balloon in dballoons: sub = submissions[balloon.submission_id] team = app.contest.teams[sub.team] problem = app.contest.problems[sub.problem] balloons.append( Balloon(balloon.balloon_id, sub, team, problem, balloon.delivered)) return render_template( 'judge/balloons.html', balloons=sorted(balloons, key=lambda balloon: balloon.submission.submitted))
def reload(): app.contest = Contest.load(app.opts.contest) return redirect(url_for('judge.index'))
def logout(): session.pop('judge', '') return redirect(url_for('judge.login'))
def logout(): session.pop('team', '') return redirect(url_for('index'))