If file directory doesn't exist, create it
This commit is contained in:
parent
500462ec00
commit
8c295b6c13
2 changed files with 6 additions and 2 deletions
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue