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 view_submission(sub_id): sub = Submission.query.filter_by(id=sub_id).first() if not sub: abort(404) if request.method == 'POST': if 'score' in request.form and 'judge_response' in request.form: sub.score = request.form['score'] sub.judge_response = request.form['judge_response'] 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 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 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 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 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 view_problem(problem_id, sub_id): problem = app.contest.problems.get(problem_id) phase = app.contest.get_current_phase() team = get_team() sub = None 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)) if ('answer_file' in request.files or 'answer' in request.form): if 'answer_file' in request.files: answer = request.files['answer_file'].read() try: answer = answer.decode('utf-8') except UnicodeDecodeError: answer = text.bytes2unicode(answer) if 'answer_file' not in request.files or not answer: answer = request.form['answer'] score, response = problem.score(answer) sub = Submission( team=team.name, problem=problem_id, answer=answer, submitted=datetime.datetime.now(), score=score, points=int(round((score/100) * problem.points)), judge_response=response ) app.db.session.add(sub) app.db.session.flush() app.db.session.commit() else: abort(400) # return redirect(url_for('default.list_submissions')) if problem_id not in phase.visible_problems: abort(404) 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) if team: max_sub = Submission.query.filter_by(problem=problem_id, team=team.name).order_by(Submission.points.desc(), Submission.submitted.desc()).first() else: max_sub = None if max_sub is not None and sub is not None and max_sub.id == sub.id: sub = None return render_template('problem.html', problem=problem, sub=sub, max_sub=max_sub)
def logout(): session.pop('team', '') return redirect(url_for('index'))