mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2024-12-24 18:34:18 +00:00
Change add job handling (preparation for api processing)
This commit is contained in:
parent
8d47d16319
commit
ab0e79ac3b
@ -1,7 +1,8 @@
|
|||||||
from app import db
|
from app import db, logger
|
||||||
from app.jobs.forms import AddNLPJobForm, AddOCRJobForm
|
from app.jobs.forms import AddNLPJobForm, AddOCRJobForm
|
||||||
from app.models import Job, JobInput
|
from app.models import Job, JobInput
|
||||||
from flask import abort, current_app, flash, redirect, render_template, url_for
|
from flask import (abort, current_app, flash, make_response, render_template,
|
||||||
|
request, url_for)
|
||||||
from flask_login import current_user, login_required
|
from flask_login import current_user, login_required
|
||||||
from werkzeug.utils import secure_filename
|
from werkzeug.utils import secure_filename
|
||||||
from . import services
|
from . import services
|
||||||
@ -23,7 +24,9 @@ def service(service):
|
|||||||
if service not in SERVICES:
|
if service not in SERVICES:
|
||||||
abort(404)
|
abort(404)
|
||||||
add_job_form = SERVICES[service]['add_job_form']()
|
add_job_form = SERVICES[service]['add_job_form']()
|
||||||
if add_job_form.validate_on_submit():
|
if add_job_form.is_submitted():
|
||||||
|
if not add_job_form.validate():
|
||||||
|
return make_response(add_job_form.errors, 400)
|
||||||
service_args = []
|
service_args = []
|
||||||
if service == 'nlp':
|
if service == 'nlp':
|
||||||
service_args.append('-l {}'.format(add_job_form.language.data))
|
service_args.append('-l {}'.format(add_job_form.language.data))
|
||||||
@ -46,8 +49,11 @@ def service(service):
|
|||||||
try:
|
try:
|
||||||
os.makedirs(absolut_dir)
|
os.makedirs(absolut_dir)
|
||||||
except OSError:
|
except OSError:
|
||||||
flash('[ERROR]: Could not add job!')
|
|
||||||
job.delete()
|
job.delete()
|
||||||
|
flash('Internal Server Error')
|
||||||
|
return make_response(
|
||||||
|
{'redirect_url': url_for('services.service', service='ocr')},
|
||||||
|
500)
|
||||||
else:
|
else:
|
||||||
for file in add_job_form.files.data:
|
for file in add_job_form.files.data:
|
||||||
filename = secure_filename(file.filename)
|
filename = secure_filename(file.filename)
|
||||||
@ -58,7 +64,8 @@ def service(service):
|
|||||||
job.status = 'submitted'
|
job.status = 'submitted'
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
flash('Job added!')
|
flash('Job added!')
|
||||||
return redirect(url_for('jobs.job', job_id=job.id))
|
return make_response(
|
||||||
|
{'redirect_url': url_for('jobs.job', job_id=job.id)}, 201)
|
||||||
return render_template('services/{}.html.j2'.format(service),
|
return render_template('services/{}.html.j2'.format(service),
|
||||||
title=SERVICES[service]['name'],
|
title=SERVICES[service]['name'],
|
||||||
add_job_form=add_job_form)
|
add_job_form=add_job_form)
|
||||||
|
@ -14,9 +14,15 @@ function SubmitAddJobForm(newJobFormElement, progressModalElement, request) {
|
|||||||
progressModalElement.querySelector(".determinate").style.width = progressInPercent;
|
progressModalElement.querySelector(".determinate").style.width = progressInPercent;
|
||||||
});
|
});
|
||||||
request.addEventListener("load", function(event) {
|
request.addEventListener("load", function(event) {
|
||||||
console.log(request.response);
|
if (request.status === 201) {
|
||||||
newJobFormElement.reset();
|
window.location.href = JSON.parse(this.responseText)['redirect_url'];
|
||||||
location.reload();
|
}
|
||||||
|
if (request.status === 400) {
|
||||||
|
console.log(JSON.parse(this.responseText));
|
||||||
|
}
|
||||||
|
if (request.status === 500) {
|
||||||
|
location.reload();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
request.addEventListener("abort", function(event) {
|
request.addEventListener("abort", function(event) {
|
||||||
progressModalElement.querySelector(".progress-in-percent").innerHTML = "0%";
|
progressModalElement.querySelector(".progress-in-percent").innerHTML = "0%";
|
||||||
|
Loading…
Reference in New Issue
Block a user