Delete files in db model methods.

This commit is contained in:
Patrick Jentsch committed 2020-07-10 11:36:54 +02:00
1 parent f86f3f4fd5
commit 7f8797d227
8 files changed
+84 -93

No files matched your search

+4 -8
View File
@@ -1,17 +1,13 @@
from .. import db
from ..decorators import background
from ..models import Result
import os
import shutil
@background
def delete_result(result_id, *args, **kwargs):
app = kwargs['app']
with app.app_context():
with kwargs['app'].app_context():
result = Result.query.get(result_id)
if result is None:
return
result_file_path = os.path.join(app.config['NOPAQUE_STORAGE'],
result.file[0].dir)
shutil.rmtree(result_file_path)
raise Exception('Result {} not found'.format(result_id))
result.delete() # cascades down and also deletes ResultFile
db.session.commit()