mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2025-06-14 10:00:40 +00:00
Delete files in db model methods.
This commit is contained in:
@ -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()
|
||||
|
Reference in New Issue
Block a user