mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2024-11-15 01:05:42 +00:00
68 lines
2.3 KiB
Python
68 lines
2.3 KiB
Python
from flask import abort, jsonify
|
|
from flask_login import current_user, login_required
|
|
from . import api
|
|
|
|
|
|
@api.route('/v1.0/corpora')
|
|
@login_required
|
|
def corpora():
|
|
corpora = []
|
|
for corpus in current_user.corpora.all():
|
|
corpora.append({'id': corpus.id,
|
|
'creation_date': corpus.creation_date.timestamp(),
|
|
'description': corpus.description,
|
|
'title': corpus.title})
|
|
return jsonify(corpora)
|
|
|
|
|
|
@api.route('/v1.0/corpora/<int:corpus_id>')
|
|
@login_required
|
|
def corpus(corpus_id):
|
|
corpus = current_user.corpora.filter_by(id=corpus_id).first()
|
|
if not corpus:
|
|
return abort(404)
|
|
return jsonify({'id': corpus.id,
|
|
'creation_date': corpus.creation_date,
|
|
'description': corpus.description,
|
|
'title': corpus.title})
|
|
|
|
|
|
@api.route('/v1.0/jobs')
|
|
@login_required
|
|
def jobs():
|
|
jobs = []
|
|
for job in current_user.jobs.all():
|
|
jobs.append({'id': job.id,
|
|
'creation_date': job.creation_date.timestamp(),
|
|
'description': job.description,
|
|
'end_date': (job.end_date.timestamp() if job.end_date else
|
|
None),
|
|
'mem_mb': job.mem_mb,
|
|
'n_cores': job.n_cores,
|
|
'service': job.service,
|
|
'service_args': job.service_args,
|
|
'service_version': job.service_version,
|
|
'status': job.status,
|
|
'title': job.title})
|
|
return jsonify(jobs)
|
|
|
|
|
|
@api.route('/v1.0/jobs/<int:job_id>')
|
|
@login_required
|
|
def job(job_id):
|
|
job = current_user.jobs.filter_by(id=job_id).first()
|
|
if not job:
|
|
return abort(404)
|
|
return jsonify({'id': job.id,
|
|
'creation_date': job.creation_date.timestamp(),
|
|
'description': job.description,
|
|
'end_date': (job.end_date.timestamp() if job.end_date else
|
|
None),
|
|
'mem_mb': job.mem_mb,
|
|
'n_cores': job.n_cores,
|
|
'service': job.service,
|
|
'service_args': job.service_args,
|
|
'service_version': job.service_version,
|
|
'status': job.status,
|
|
'title': job.title})
|