feat: add project deadline check
This commit is contained in:
@@ -7,6 +7,10 @@ import re
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
project_deadlines = {
|
||||
"experiment_knn": "2024-10-17 23:59:59",
|
||||
}
|
||||
|
||||
# 上传文件的路径
|
||||
UPLOAD_FOLDER = "./uploads"
|
||||
os.makedirs(UPLOAD_FOLDER, exist_ok=True)
|
||||
@@ -86,6 +90,18 @@ def write_to_csv(data, project):
|
||||
writer.writerow(data)
|
||||
|
||||
|
||||
def is_past_deadline(project):
|
||||
# 当前时间
|
||||
current_time = datetime.datetime.now()
|
||||
# 截止时间
|
||||
deadline_str = project_deadlines.get(project)
|
||||
|
||||
if deadline_str:
|
||||
deadline = datetime.datetime.strptime(deadline_str, "%Y-%m-%d %H:%M:%S")
|
||||
return current_time > deadline
|
||||
return False
|
||||
|
||||
|
||||
@app.route("/upload_score", methods=["POST"])
|
||||
def upload_score():
|
||||
try:
|
||||
@@ -108,6 +124,11 @@ def upload_score():
|
||||
or data["name"] == ""
|
||||
):
|
||||
return jsonify({"message": "姓名不合规,不记录成绩!"}), 400
|
||||
|
||||
# 检查截止时间
|
||||
if is_past_deadline(data["project"]):
|
||||
return jsonify({"message": "已过成绩提交截止时间,上传成绩失败!"}), 403
|
||||
|
||||
data["details"] = data["details"].replace("\n", "<br>")
|
||||
write_to_csv(data, data["project"])
|
||||
return jsonify({"message": "上传成绩成功!"}), 200
|
||||
|
||||
Reference in New Issue
Block a user