Exemplo n.º 1
0
def scoreboard(contest_name):
    if session.get_current_user().privilege not in (UserPrivilege.ADMIN,
                                                    UserPrivilege.TUTOR):
        return abort(403)

    contest = Contest.from_name(contest_name)

    return render_template("scoreboard.html", contest=contest)
Exemplo n.º 2
0
def user_view(username):
    user = User.from_username(username)

    if user.privilege == UserPrivilege.STANDARD and user != session.get_current_user(
    ):
        return abort(403)

    contests = Contest.of_user(user)
    return render_template("user.html", user=user, contests=contests)
Exemplo n.º 3
0
def submission_view(submission_id):
    current_user = get_current_user()
    submission = Submission.from_id(submission_id)
    if current_user is None or current_user.id != submission.user.id:
        return abort(403)

    return render_template('submission.html',
                           goals=submission.goals,
                           user=current_user,
                           id=submission.id)
Exemplo n.º 4
0
def contest_view(contest_name):
    contest = Contest.from_name(contest_name)

    if contest is None:
        return abort(404)

    user = session.get_current_user()

    if not contest.public and not contest.contains_user(user):
        return abort(403)

    return render_template("contest.html", contest=contest, user=user)
Exemplo n.º 5
0
def subscribe(contest_name):
    contest = Contest.from_name(contest_name)
    user = session.get_current_user()

    if contest is None:
        return abort(404)

    if user is None or not contest.public:
        return abort(403)

    contest.add_user(user)

    return redirect(url_for("contest.contest_view", contest_name=contest_name))
Exemplo n.º 6
0
def home():
    user = get_current_user()
    if user is None:
        return redirect(url_for("user.login"))
    contests = list(Contest.of_user(user))

    available_contests = [
        contest for contest in Contest.contests()
        if contest.public and contest not in contests
    ]
    return render_template("home.html",
                           contests=contests,
                           available_contests=available_contests,
                           user=user)
Exemplo n.º 7
0
def problem_view(contest_name, name):
    contest = Contest.from_name(contest_name)
    if contest is None:
        return abort(404)

    current_user = get_current_user()
    if contest is None or not contest.contains_user(current_user):
        return abort(403)

    if request.method == "POST" and current_user is None:
        return abort(401)

    problem = Problem.from_name(name)
    if problem is None:
        return abort(404)

    error = None
    if request.method == "POST":
        try:
            return evaluate(current_user, problem, contest)
        except RuntimeError as e:
            error = str(e)

    subs = list(
        Submission.from_user_and_problem_and_contest(current_user, problem,
                                                     contest))

    correct_goals = {
        sub.id: sum(val for val in sub.goals.values() if val is not None)
        for sub in subs
    }

    return render_template("problem.html",
                           correct_goals=correct_goals,
                           error=error,
                           problem=problem,
                           contest=contest,
                           user=current_user,
                           submissions=subs)
Exemplo n.º 8
0
def download(submission_id, filename):
    sub = Submission.from_id(submission_id)
    if get_current_user().id != sub.user_id:
        return abort(403)
    assert sub.filename == filename
    return send_file(sub.path)
Exemplo n.º 9
0
def user_():
    user = session.get_current_user()
    if user is not None:
        return redirect(url_for("user.user_view", username=user.username))
    return redirect(url_for("user.login"))