mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2024-12-25 02:44:18 +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 flask_login import current_user, login_required
|
||||||
from ..models import Corpus, User, Job
|
from ..models import Corpus, User, Job
|
||||||
from ..tables import AdminUserTable, AdminUserItem
|
from ..tables import AdminUserTable, AdminUserItem
|
||||||
@ -81,17 +81,37 @@ def job(job_id):
|
|||||||
if file == 'output':
|
if file == 'output':
|
||||||
continue
|
continue
|
||||||
files[file] = {}
|
files[file] = {}
|
||||||
files[file]['path'] = os.path.join(dir, file)
|
files[file]['path'] = os.path.join(file)
|
||||||
if job.status == 'complete':
|
if job.status == 'complete':
|
||||||
files[file]['results'] = {}
|
files[file]['results'] = {}
|
||||||
results_dir = os.path.join(dir, 'output', file)
|
results_dir = os.path.join(dir, 'output', file)
|
||||||
for result in os.listdir(results_dir):
|
for result in os.listdir(results_dir):
|
||||||
files[file]['results'][result] = {}
|
files[file]['results'][result] = {}
|
||||||
files[file]['results'][result]['path'] = os.path.join(
|
files[file]['results'][result]['path'] = os.path.join(
|
||||||
results_dir, result
|
'output', files[file]['path'], result
|
||||||
)
|
)
|
||||||
|
|
||||||
return render_template('main/jobs/job.html.j2',
|
return render_template('main/jobs/job.html.j2',
|
||||||
files=files,
|
files=files,
|
||||||
job=job,
|
job=job,
|
||||||
title='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>
|
</div>
|
||||||
<p>
|
<p>
|
||||||
{% for file in files %}
|
{% 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 }}
|
<i class="material-icons left">file_download</i>{{ file }}
|
||||||
</a>
|
</a>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
@ -84,7 +84,7 @@
|
|||||||
<p>
|
<p>
|
||||||
{% for file in files %}
|
{% for file in files %}
|
||||||
{% for result in files[file]['results'] %}
|
{% 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 }}
|
<i class="material-icons left">file_download</i>{{ result }}
|
||||||
</a>
|
</a>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
Loading…
Reference in New Issue
Block a user