Adds delete_file util (#239)

This commit is contained in:
Kevin Chung
2017-04-08 01:34:22 -04:00
committed by GitHub
parent fd22ef98dc
commit 72f7eeb0a4
2 changed files with 12 additions and 5 deletions

View File

@@ -163,11 +163,8 @@ def admin_files(chalid):
return jsonify(json_data)
if request.method == 'POST':
if request.form['method'] == "delete":
f = Files.query.filter_by(id=request.form['file']).first_or_404()
upload_folder = os.path.join(app.root_path, app.config['UPLOAD_FOLDER'])
if os.path.exists(os.path.join(upload_folder, f.location)): # Some kind of os.path.isfile issue on Windows...
os.unlink(os.path.join(upload_folder, f.location))
db.session.delete(f)
utils.delete_file(request.form['file'])
db.session.commit()
db.session.close()
return '1'