mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2024-12-24 02:24:20 +00:00
Add download helper for dev process.
This commit is contained in:
parent
e00d34ef81
commit
fa2827608c
@ -1,4 +1,4 @@
|
||||
from flask import abort, current_app, flash, redirect, render_template, url_for
|
||||
from flask import abort, current_app, flash, redirect, request, render_template, url_for, send_from_directory
|
||||
from flask_login import current_user, login_required
|
||||
from ..models import Corpus, User, Job
|
||||
from ..tables import AdminUserTable, AdminUserItem
|
||||
@ -81,17 +81,37 @@ def job(job_id):
|
||||
if file == 'output':
|
||||
continue
|
||||
files[file] = {}
|
||||
files[file]['path'] = os.path.join(dir, file)
|
||||
files[file]['path'] = os.path.join(file)
|
||||
if job.status == 'complete':
|
||||
files[file]['results'] = {}
|
||||
results_dir = os.path.join(dir, 'output', file)
|
||||
for result in os.listdir(results_dir):
|
||||
files[file]['results'][result] = {}
|
||||
files[file]['results'][result]['path'] = os.path.join(
|
||||
results_dir, result
|
||||
'output', files[file]['path'], result
|
||||
)
|
||||
|
||||
return render_template('main/jobs/job.html.j2',
|
||||
files=files,
|
||||
job=job,
|
||||
title='Job')
|
||||
|
||||
|
||||
@main.route('/jobs/<int:job_id>/download')
|
||||
@login_required
|
||||
def job_download(job_id):
|
||||
file = request.args.get('file')
|
||||
job = Job.query.filter_by(id=job_id).first()
|
||||
if not file or not job:
|
||||
print('Job not found.')
|
||||
abort(404)
|
||||
elif not job.user_id == current_user.id:
|
||||
print('Job does not belong to current user.')
|
||||
abort(403)
|
||||
dir = os.path.join(current_app.config['OPAQUE_STORAGE'],
|
||||
str(current_user.id),
|
||||
'jobs',
|
||||
str(job.id))
|
||||
print(dir)
|
||||
print(file)
|
||||
return send_from_directory(directory=dir, filename=file, as_attachment=True)
|
||||
|
@ -72,7 +72,7 @@
|
||||
</div>
|
||||
<p>
|
||||
{% for file in files %}
|
||||
<a href="file://{{ files[file]['path'] }}" class="waves-effect waves-light btn-small">
|
||||
<a href="{{ url_for('main.job_download', job_id=job.id, file=files[file]['path']) }}" class="waves-effect waves-light btn-small">
|
||||
<i class="material-icons left">file_download</i>{{ file }}
|
||||
</a>
|
||||
{% endfor %}
|
||||
@ -84,7 +84,7 @@
|
||||
<p>
|
||||
{% for file in files %}
|
||||
{% for result in files[file]['results'] %}
|
||||
<a href="file://{{ files[file]['results'][result]['path'] }}" class="waves-effect waves-light btn-small">
|
||||
<a href="{{ url_for('main.job_download', job_id=job.id, file=files[file]['results'][result]['path']) }}" class="waves-effect waves-light btn-small">
|
||||
<i class="material-icons left">file_download</i>{{ result }}
|
||||
</a>
|
||||
{% endfor %}
|
||||
|
Loading…
Reference in New Issue
Block a user