mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2024-11-15 01:05:42 +00:00
55 lines
1.7 KiB
Python
55 lines
1.7 KiB
Python
from flask import abort, flash, Markup, render_template, url_for
|
|
from flask_login import login_required
|
|
from app import db
|
|
from app.decorators import permission_required
|
|
from app.models import TesseractOCRModel, Permission
|
|
from . import bp
|
|
from .forms import ContributionForm
|
|
|
|
|
|
@bp.before_request
|
|
@login_required
|
|
@permission_required(Permission.CONTRIBUTE)
|
|
def before_request():
|
|
pass
|
|
|
|
|
|
@bp.route('')
|
|
def contributions():
|
|
pass
|
|
|
|
|
|
@bp.route('/tesseract-ocr-pipeline-models', methods=['GET', 'POST'])
|
|
def tesseract_ocr_pipeline_models():
|
|
form = ContributionForm(
|
|
prefix='contribute-tesseract-ocr-pipeline-model-form'
|
|
)
|
|
if form.is_submitted():
|
|
if not form.validate():
|
|
response = {'errors': form.errors}
|
|
return response, 400
|
|
try:
|
|
tesseract_ocr_model = TesseractOCRModel.create(
|
|
form.file.data,
|
|
compatible_service_versions=form.compatible_service_versions.data,
|
|
description=form.description.data,
|
|
publisher=form.publisher.data,
|
|
publisher_url=form.publisher_url.data,
|
|
publishing_url=form.publishing_url.data,
|
|
publishing_year=form.publishing_year.data,
|
|
shared=form.shared.data,
|
|
title=form.title.data,
|
|
version=form.version.data
|
|
)
|
|
except OSError:
|
|
abort(500)
|
|
db.session.commit()
|
|
message = Markup(f'Model "{tesseract_ocr_model.title}" created')
|
|
flash(message)
|
|
return {}, 201, {'Location': url_for('contributions.contributions')}
|
|
return render_template(
|
|
'contributions/contribute.html.j2',
|
|
form=form,
|
|
title='Contribution'
|
|
)
|