From 8c295b6c13322f669b8a4f9848a2deac29cd0036 Mon Sep 17 00:00:00 2001 From: James Wang Date: Wed, 6 Jan 2016 01:28:19 +0000 Subject: [PATCH] If file directory doesn't exist, create it --- server/api/problem.py | 4 ++-- server/app.py | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/server/api/problem.py b/server/api/problem.py index f02d4a8..88c436f 100644 --- a/server/api/problem.py +++ b/server/api/problem.py @@ -24,8 +24,7 @@ def problem_add(): name_exists = Problems.query.filter_by(name=name).first() if name_exists: - return { "success":0, "message": "Problem name already taken." } - + return { "success": 0, "message": "Problem name already taken." } problem = Problems(name, category, description, hint, flag, value) db.session.add(problem) db.session.commit() @@ -38,6 +37,7 @@ def problem_add(): continue file_path = os.path.join(app.config["UPLOAD_FOLDER"], filename) + _file.save(file_path) db_file = Files(problem.pid, "/".join(file_path.split("/")[2:])) db.session.add(db_file) diff --git a/server/app.py b/server/app.py index 7ba7b69..afe1094 100644 --- a/server/app.py +++ b/server/app.py @@ -4,6 +4,7 @@ from flask import Flask import api import config import json +import os app = Flask(__name__) @@ -11,6 +12,9 @@ app.config["SQLALCHEMY_DATABASE_URI"] = config.SQLALCHEMY_DATABASE_URI app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = config.SQLALCHEMY_TRACK_MODIFICATIONS app.config["UPLOAD_FOLDER"] = config.UPLOAD_FOLDER +if not os.path.exists(app.config["UPLOAD_FOLDER"]): + os.makedirs(app.config["UPLOAD_FOLDER"]) + with app.app_context(): from api.models import db, Files, Teams, Problems, Solves, Users db.init_app(app)