If file directory doesn't exist, create it

This commit is contained in:
James Wang 2016-01-06 01:28:19 +00:00
parent 500462ec00
commit 8c295b6c13
2 changed files with 6 additions and 2 deletions

View file

@ -24,8 +24,7 @@ def problem_add():
name_exists = Problems.query.filter_by(name=name).first() name_exists = Problems.query.filter_by(name=name).first()
if name_exists: 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) problem = Problems(name, category, description, hint, flag, value)
db.session.add(problem) db.session.add(problem)
db.session.commit() db.session.commit()
@ -38,6 +37,7 @@ def problem_add():
continue continue
file_path = os.path.join(app.config["UPLOAD_FOLDER"], filename) file_path = os.path.join(app.config["UPLOAD_FOLDER"], filename)
_file.save(file_path) _file.save(file_path)
db_file = Files(problem.pid, "/".join(file_path.split("/")[2:])) db_file = Files(problem.pid, "/".join(file_path.split("/")[2:]))
db.session.add(db_file) db.session.add(db_file)

View file

@ -4,6 +4,7 @@ from flask import Flask
import api import api
import config import config
import json import json
import os
app = Flask(__name__) 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["SQLALCHEMY_TRACK_MODIFICATIONS"] = config.SQLALCHEMY_TRACK_MODIFICATIONS
app.config["UPLOAD_FOLDER"] = config.UPLOAD_FOLDER 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(): with app.app_context():
from api.models import db, Files, Teams, Problems, Solves, Users from api.models import db, Files, Teams, Problems, Solves, Users
db.init_app(app) db.init_app(app)