diff --git a/src/application.py b/src/application.py index fe0720d..84c317b 100644 --- a/src/application.py +++ b/src/application.py @@ -221,17 +221,12 @@ def dl_file(problem_id): @app.route("/dl//.zip") @login_required def dl_contest(contest_id, problem_id): - contest = db.execute("SELECT * FROM contests WHERE id=?", contest_id) - if len(contest) == 0: + from views.contest import _get_contest, _get_problem + _, err = _get_contest(contest_id) + if err: return abort(404) - # Ensure contest started or user is admin - start = parse_datetime(contest[0]["start"]) - if datetime.utcnow() < start and not check_perm(["ADMIN", "SUPERADMIN", "CONTENT_MANAGER"]): - return abort(404) - problem = db.execute(("SELECT * FROM contest_problems WHERE contest_id=? " - "AND problem_id=?"), contest_id, problem_id) - if len(problem) == 0 or (problem[0]["status"] == PROBLEM_STAT["DRAFT"] and - not check_perm(["ADMIN", "SUPERADMIN"])): + _, err = _get_problem(contest_id, problem_id) + if err: return abort(404) return send_from_directory("dl/", f"{contest_id}/{problem_id}.zip", as_attachment=True) diff --git a/src/migrate.py b/src/migrate.py index 6710b7d..f367028 100644 --- a/src/migrate.py +++ b/src/migrate.py @@ -38,15 +38,18 @@ 'point_value' integer NOT NULL DEFAULT(0), 'category' varchar(64), 'flag' varchar(256) NOT NULL, - 'status' integer NOT NULL DEFAULT(0), + 'publish_timestamp' datetime DEFAULT(datetime('now')), 'score_min' integer NOT NULL DEFAULT(0), 'score_max' integer NOT NULL DEFAULT(0), 'score_users' integer NOT NULL DEFAULT(-1), 'flag_hint' varchar(256) NOT NULL DEFAULT(''), 'instanced' boolean NOT NULL DEFAULT(0), UNIQUE(contest_id, problem_id) ON CONFLICT ABORT -)""") +); +""") db.execute("INSERT INTO contest_problems_migration SELECT contest_id, problem_id, name, point_value, category, flag, draft, score_min, score_max, score_users, flag_hint, instanced FROM contest_problems") +db.execute("UPDATE contest_problems_migration SET publish_timestamp = datetime('now') WHERE publish_timestamp = 0") +db.execute("UPDATE contest_problems_migration SET publish_timestamp = NULL WHERE publish_timestamp = 1") db.execute("DROP TABLE contest_problems") db.execute("ALTER TABLE contest_problems_migration RENAME TO contest_problems") diff --git a/src/schema.sql b/src/schema.sql index 81e3ec2..f87fd26 100644 --- a/src/schema.sql +++ b/src/schema.sql @@ -76,7 +76,7 @@ CREATE TABLE 'contest_problems' ( 'point_value' integer NOT NULL DEFAULT(0), 'category' varchar(64), 'flag' varchar(256) NOT NULL, - 'status' integer NOT NULL DEFAULT(0), -- 0: published, 1: draft + 'publish_timestamp' datetime DEFAULT(datetime('now')), 'score_min' integer NOT NULL DEFAULT(0), 'score_max' integer NOT NULL DEFAULT(0), 'score_users' integer NOT NULL DEFAULT(-1), diff --git a/src/templates/contest/problem/create.html b/src/templates/contest/problem/create.html index 4154591..2a287f9 100644 --- a/src/templates/contest/problem/create.html +++ b/src/templates/contest/problem/create.html @@ -107,9 +107,22 @@

Create Problem

-
- - +
+
+ Publish Now +
+ +
+ Publish Later +
+
+ + +
@@ -177,5 +190,14 @@

Create Problem

.querySelectorAll("input") .forEach(e => e.setAttribute("required", "")); } + + document.querySelector("form").onsubmit = function(event) { + var formPub = this.querySelector("#publish_timestamp"); + if (formPub.value !== "") { + var pub = new Date(formPub.value).toISOString(); + formPub.setAttribute("type", "text"); + formPub.value = pub; + } + } -{% endblock %} +{% endblock %} \ No newline at end of file diff --git a/src/templates/contest/problem/edit.html b/src/templates/contest/problem/edit.html index b8e203d..d12c59a 100644 --- a/src/templates/contest/problem/edit.html +++ b/src/templates/contest/problem/edit.html @@ -4,7 +4,7 @@ {% block active %}Contests{% endblock %} {% block preload %} - + {% endblock %} {% block main %} @@ -84,6 +84,33 @@

Edit {{ data["name"] }}

+
+
+ Publish Now +
+ +
+ Publish Later +
+
+ + +
+
@@ -141,5 +168,27 @@

Edit {{ data["name"] }}

hints.value = b["data"]["hints"]; updateHints(); }); + + document.querySelectorAll(".dtl").forEach(function (e) { + var split = e.getAttribute("value").split(" "); + var dateSplit = split[0].split("-"); + var final = dateSplit[1] + "/" + dateSplit[2] + "/" + dateSplit[0] + " " + split[1]; + var parsed = new Date(final + " UTC").toString().split(" "); + e.value = `${ parsed[3] }-${ getMonthFromString(parsed[1]) }-${ parsed[2] }T${ parsed[4] }`; + + function getMonthFromString(mon) { + var str = (new Date(Date.parse(mon + " 1, 2012")).getMonth() + 1).toString(); + return str.length == 2 ? str : "0" + str; + } + }); + + document.querySelector("form").onsubmit = function(event) { + var formPub = this.querySelector("#publish_timestamp"); + if (formPub.value !== "") { + var pub = new Date(formPub.value).toISOString(); + formPub.setAttribute("type", "text"); + formPub.value = pub; + } + } {% endblock %} diff --git a/src/templates/contest/problem/problem.html b/src/templates/contest/problem/problem.html index 859e59c..00b483e 100644 --- a/src/templates/contest/problem/problem.html +++ b/src/templates/contest/problem/problem.html @@ -163,7 +163,7 @@

Live Instance


Edit problem
Download problem - {% if data["status"] == 1 %} + {% if data["show_publish_btn"] %}
Publish problem @@ -201,7 +201,7 @@

Live Instance

document.getElementById("hint").classList.toggle("hidden"); }); -{% if data["status"] == 1 %} +{% if data["show_publish_btn"] %}