mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2025-06-12 00:50:40 +00:00
Use enums where appropriate. This commit includes new migrations that are NOT compatible with older nopaque instances
This commit is contained in:
@ -1,7 +1,13 @@
|
||||
from app.models import TesseractOCRModel
|
||||
from flask_wtf import FlaskForm
|
||||
from wtforms import (BooleanField, MultipleFileField, SelectField, StringField,
|
||||
SubmitField, ValidationError)
|
||||
from wtforms import (
|
||||
BooleanField,
|
||||
MultipleFileField,
|
||||
SelectField,
|
||||
StringField,
|
||||
SubmitField,
|
||||
ValidationError
|
||||
)
|
||||
from wtforms.validators import DataRequired, Length
|
||||
from . import SERVICES
|
||||
|
||||
@ -25,7 +31,7 @@ class AddSpacyNLPJobForm(AddJobForm):
|
||||
|
||||
def validate_encoding_detection(self, field):
|
||||
service_info = SERVICES['spacy-nlp']['versions'][self.version.data]
|
||||
if field.data and 'encoding_detection' not in service_info:
|
||||
if field.data and 'encoding_detection' not in service_info['methods']:
|
||||
raise ValidationError('Encoding detection is not available')
|
||||
|
||||
def validate_files(form, field):
|
||||
@ -41,7 +47,7 @@ class AddSpacyNLPJobForm(AddJobForm):
|
||||
version = kwargs.pop('version', SERVICES['spacy-nlp']['latest_version']) # noqa
|
||||
super().__init__(*args, **kwargs)
|
||||
service_info = SERVICES['spacy-nlp']['versions'][version]
|
||||
if 'check_encoding' not in service_info['methods']:
|
||||
if 'encoding_detection' not in service_info['methods']:
|
||||
self.encoding_detection.render_kw = {'disabled': True}
|
||||
self.model.choices += [(x, y) for x, y in service_info['models'].items()] # noqa
|
||||
self.version.choices = [(x, x) for x in SERVICES['spacy-nlp']['versions']] # noqa
|
||||
@ -60,7 +66,7 @@ class AddTesseractOCRJobForm(AddJobForm):
|
||||
|
||||
def validate_binarization(self, field):
|
||||
service_info = SERVICES['tesseract-ocr']['versions'][self.version.data]
|
||||
if field.data and 'binarization' not in service_info:
|
||||
if field.data and 'binarization' not in service_info['methods']:
|
||||
raise ValidationError('Binarization is not available')
|
||||
|
||||
def validate_files(self, field):
|
||||
|
@ -1,21 +1,29 @@
|
||||
from app import hashids
|
||||
from flask import (abort, current_app, flash, make_response, render_template,
|
||||
request, url_for)
|
||||
from app import db, hashids
|
||||
from app.models import Job, JobInput, JobStatus
|
||||
from flask import (
|
||||
abort,
|
||||
current_app,
|
||||
flash,
|
||||
make_response,
|
||||
render_template,
|
||||
request,
|
||||
url_for
|
||||
)
|
||||
from flask_login import current_user, login_required
|
||||
from werkzeug.utils import secure_filename
|
||||
from . import bp
|
||||
from . import SERVICES
|
||||
from .. import db
|
||||
from .forms import AddJobForms
|
||||
from ..models import Job, JobInput
|
||||
import json
|
||||
|
||||
|
||||
@bp.route('/corpus-analysis')
|
||||
@login_required
|
||||
def corpus_analysis():
|
||||
return render_template('services/corpus_analysis.html.j2',
|
||||
title='Corpus analysis')
|
||||
return render_template(
|
||||
'services/corpus_analysis.html.j2',
|
||||
title='Corpus analysis'
|
||||
)
|
||||
|
||||
|
||||
@bp.route('/<service>', methods=['GET', 'POST'])
|
||||
@ -47,7 +55,6 @@ def service(service):
|
||||
service=service,
|
||||
service_args=json.dumps(service_args),
|
||||
service_version=form.version.data,
|
||||
status='preparing',
|
||||
title=form.title.data
|
||||
)
|
||||
db.session.add(job)
|
||||
@ -77,7 +84,7 @@ def service(service):
|
||||
db.session.rollback()
|
||||
flash('Internal Server Error', 'error')
|
||||
return make_response({'redirect_url': url_for('.service', service=service)}, 500) # noqa
|
||||
job.status = 'submitted'
|
||||
job.status = JobStatus.SUBMITTED
|
||||
db.session.commit()
|
||||
flash(f'Job "{job.title}" added', 'job')
|
||||
return make_response({'redirect_url': url_for('jobs.job', job_id=job.id)}, 201) # noqa
|
||||
|
Reference in New Issue
Block a user