def contest_view(contest_id): # レート更新 if "update_rate" in request.form.keys() and is_admin(session["user_id"]): update_contest_rate(contest_id) return redirect(base_url + "/contest_list") # ヒント開封 if "hint_open" in request.form.keys(): open_hint(contest_id, request.form["hint_open"], session["user_id"]) return redirect(base_url + "/contest/" + contest_id) ranking_data, submission_data = get_ranking_data(contest_id) contest_top = markdown2.markdown(get_contest_top(contest_id), extras=['fenced-code-blocks']) contest_data = get_contest_data(contest_id) problem_list = get_contest_problems(contest_id, session["user_id"]) hint_info_list = get_hint_data(contest_id, session["user_id"]) # コンテストが始まっているか start_time = datetime.strptime(contest_data.start_time, "%Y-%m-%d %H:%M:%S") if (datetime.now() < start_time) and (not is_admin(session["user_id"])): problem_list = {} return render_template("contest.html", session=session["user_id"], contest_data=contest_data, contest_top=Markup(contest_top), ranking_list=ranking_data, submission_data=submission_data, is_admin=is_admin(session["user_id"]), problem_list=problem_list, hint_info_list=hint_info_list)
def add_problem_route(): # 管理者かどうか確認 if not is_admin(session["user_id"]): return redirect(base_url) add_result = None # 問題追加 if request.method == "POST": problem_name = request.form["problem_name"] scoring = int(request.form["scoring"]) open_date = request.form["open_date"] open_time = request.form["open_time"] problem_body = request.form["problem_body"] score_data = request.form["score_data"] lang_rest = request.form.getlist("lang_rest") add_result, problem_id = add_problem(problem_name, scoring, open_date, open_time, problem_body, score_data, lang_rest) # 入出力ファイル保存 if add_result: save_io_file(problem_id, request.files) return render_template("add_problem.html", session=session["user_id"], add_result=add_result)
def before_request(): if "user_id" not in session.keys(): session["user_id"] = None # ログインする必要があるか判断 enough_login = True for url in no_login_ok_url: if url in request.url: enough_login = False if enough_login and session["user_id"] is None: return redirect(base_url + "/login") # ログイン制限 login_rest = False if session["user_id"] is not None: # 特定のユーザを制限 if session["user_id"] in config_file["user"]["login_rest_users"]: login_rest = True # 管理者以外制限 if config_file["user"]["login_rest_users"] == "all" and not is_admin(session["user_id"]): login_rest = True if login_rest: if "/logout" not in request.url and "/login_rest" not in request.url: return redirect(base_url + "/login_rest")
def add_contest_route(): # 管理者かどうか確認 if not is_admin(session["user_id"]): return redirect(base_url) add_result = None # 問題追加 if request.method == "POST": contest_name = request.form["contest_name"] contest_top = request.form["contest_top"] start_date = request.form["start_date"] start_time = request.form["start_time"] end_date = request.form["end_date"] end_time = request.form["end_time"] frozen_date = request.form["frozen_date"] frozen_time = request.form["frozen_time"] rate_limit = request.form["rate_limit"] problems = request.form.getlist("problems") hint_info = request.form["hint_info"] add_result = add_contest(contest_name, contest_top, start_date + " " + start_time, end_date + " " + end_time, frozen_date + " " + frozen_time, rate_limit, problems, hint_info) return render_template("add_contest.html", session=session["user_id"], add_result=add_result, problems=get_all_problem_with_status( session["user_id"], False))
def submission_view(submission_id): # リジャッジ if "rejudge" in request.form.keys() and is_admin(session["user_id"]): add_judge_job(submission_id) return redirect(base_url + "/submission_list/all") # 提出削除 if "rm_submission" in request.form.keys() and is_admin(session["user_id"]): remove_submission(submission_id) return redirect(base_url + "/submission_list/all") # 提出詳細ページ描画に必要な情報を取得 submission_data, code, open_code = get_data_for_submission_page( session["user_id"], submission_id) return render_template("submission.html", session=session["user_id"], submission_data=submission_data, code=code, open_code=open_code, is_admin=is_admin(session["user_id"]))
def control_panel_route(): # 管理者かどうか判定 if not is_admin(session["user_id"]): return redirect(base_url) # 必要な情報取得 problem_list = get_all_problem_with_status(session["user_id"], False) contest_list = get_all_contest() return render_template("control_panel.html", problem_list=problem_list, contest_list=contest_list, session=session["user_id"])
def edit_contest_route(contest_id): # 管理者かどうか確認 if not is_admin(session["user_id"]): return redirect(base_url) update_result = None # 情報更新 if request.method == "POST": contest_name = request.form["contest_name"] contest_top = request.form["contest_top"] start_date = request.form["start_date"] start_time = request.form["start_time"] end_date = request.form["end_date"] end_time = request.form["end_time"] frozen_date = request.form["frozen_date"] frozen_time = request.form["frozen_time"] rate_limit = request.form["rate_limit"] problems = request.form.getlist("problems") hint_info = request.form["hint_info"] update_result = update_contest(contest_id, contest_name, contest_top, start_date + " " + start_time, end_date + " " + end_time, frozen_date + " " + frozen_time, rate_limit, problems, hint_info) # 必要な情報を取得する contest_top = get_contest_top(contest_id) all_problems = get_all_problem_with_status(session["user_id"], False) contest_data = get_contest_data(contest_id) hint_json_str = get_contest_hint(contest_id) hint_json = json.loads(hint_json_str) hint_json_format = json.dumps( hint_json, indent=4).encode("ascii").decode("unicode-escape") return render_template("edit_contest.html", session=session["user_id"], update_result=update_result, all_problems=all_problems, contest_top=contest_top, contest=contest_data, hint_json_str=hint_json_format)
def edit_problem_route(problem_id): # 管理者かどうか確認 if not is_admin(session["user_id"]): return redirect(base_url) update_result = None # 問題更新(POSTのとき) if request.method == "POST": problem_name = request.form["problem_name"] scoring = int(request.form["scoring"]) open_date = request.form["open_date"] open_time = request.form["open_time"] problem_body = request.form["problem_body"] test_case_data = request.form["test_case_data"] lang_rest = request.form.getlist("lang_rest") update_result = update_problem(problem_id, problem_name, scoring, open_date, open_time, problem_body, test_case_data, lang_rest) # 入出力ファイル保存・削除 if update_result: save_io_file(problem_id, request.files) rm_io_file(problem_id, request.form.getlist("rm_input"), request.form.getlist("rm_output")) # 必要な情報を読み込む problem_data = get_problem_data(problem_id) test_case_data = json.loads(get_test_case_data(problem_id)) test_case_data_format = json.dumps(test_case_data, indent=4) problem_body = get_problem_body(problem_id) io_file_list = get_io_file_list(problem_id) return render_template("edit_problem.html", session=session["user_id"], problem=problem_data, problem_test_case_data=test_case_data_format, problem_body=problem_body, input_file_list=io_file_list["input"], output_file_list=io_file_list["output"], update_result=update_result)