Skip to content
Snippets Groups Projects
Commit 9d6e54e9 authored by Patrick Jentsch's avatar Patrick Jentsch
Browse files

Change how job form works.

parent 787bf4c3
No related branches found
No related tags found
No related merge requests found
from flask import abort, current_app, flash, redirect, render_template, url_for
from . import services
from flask_login import current_user, login_required
from .forms import NewOCRJobForm, NewNLPJobForm
from .forms import NewNLPJobForm, NewOCRJobForm
from ..models import Job
from .. import db
import json
import os
SERVICE_REQUIREMENTS = {'nlp': {'mem_mb': 4096, 'n_cores': 2},
'ocr': {'mem_mb': 8192, 'n_cores': 4}}
SERVICES = {'nlp': {'name': 'Natural Language Processing',
'resources': {'mem_mb': 4096, 'n_cores': 2},
'new_job_form': NewNLPJobForm},
'ocr': {'name': 'Optical Character Recognition',
'resources': {'mem_mb': 8192, 'n_cores': 4},
'new_job_form': NewOCRJobForm}}
@services.route('/<service_handle>', methods=['GET', 'POST'])
@login_required
def service(service_handle):
if service_handle not in ['nlp', 'ocr']:
if service_handle not in SERVICES:
abort(404)
elif service_handle == 'nlp':
page_title = 'Natural Language Processing'
new_job_form = NewNLPJobForm()
elif service_handle == 'ocr':
page_title = 'Optical Character Recognition'
new_job_form = NewOCRJobForm()
new_job_form = SERVICES[service_handle]['new_job_form']()
if new_job_form.validate_on_submit():
_service_args = ['-l {}'.format(new_job_form.language.data)]
if service_handle == 'ocr':
......@@ -31,8 +30,8 @@ def service(service_handle):
job = Job(
creator=current_user,
description=new_job_form.description.data,
mem_mb=SERVICE_REQUIREMENTS[service_handle]['mem_mb'],
n_cores=SERVICE_REQUIREMENTS[service_handle]['n_cores'],
mem_mb=SERVICES[service_handle]['resources']['mem_mb'],
n_cores=SERVICES[service_handle]['resources']['n_cores'],
service=service_handle,
service_args=json.dumps(_service_args),
service_version=new_job_form.version.data,
......@@ -53,11 +52,14 @@ def service(service_handle):
db.session.commit()
else:
for file in new_job_form.files.data:
''' TODO: Use secure filename '''
file.save(os.path.join(dir, file.filename))
job.status = 'submitted'
db.session.commit()
flash('Job created!')
return redirect(url_for('services.{}'.format(service_handle)))
return redirect(
url_for('services.service', service_handle=service_handle)
)
return render_template('services/{}.html.j2'.format(service_handle),
title=page_title,
title=SERVICES[service_handle]['name'],
new_job_form=new_job_form)
......@@ -2,7 +2,7 @@
{% block page_content %}
<div class="col s12 m4">
<h3>Corpora</h3>
<h3>My Corpora</h3>
<p>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren,</p>
</div>
......@@ -46,7 +46,7 @@
</div>
<div class="col s12 m4">
<h3>Jobs</h3>
<h3>My Jobs</h3>
<p>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren,</p>
</div>
......
......@@ -117,7 +117,6 @@
</script>
<div class="col s12 m4">
<h2>Status:</h2>
<h3 id="title"></h3>
<p id="description"></p>
<a class="waves-effect waves-light btn" id="status"></a>
......@@ -125,6 +124,7 @@
<!-- Confirm deletion of job with modal dialogue
Modal Trigger-->
<a href="#modal-confirm-delete" class="waves-effect waves-light btn red modal-trigger"><i class="material-icons left">delete</i>Delete Job</a>
<a href="#" class="waves-effect waves-light btn"><i class="material-icons left">settings</i>Export Parameters</a>
<!-- Modal Strucutre -->
<div id="modal-confirm-delete" class="modal">
<div class="modal-content">
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment