2022-10-26 08:23:22 +00:00
|
|
|
from flask import abort, flash, Markup, render_template, url_for
|
|
|
|
from flask_login import login_required
|
|
|
|
from app import db
|
2022-09-02 11:02:04 +00:00
|
|
|
from app.decorators import permission_required
|
2022-10-26 08:23:22 +00:00
|
|
|
from app.models import TesseractOCRModel, Permission
|
2022-02-03 11:39:16 +00:00
|
|
|
from . import bp
|
2022-10-02 21:49:14 +00:00
|
|
|
from .forms import ContributionForm
|
2022-02-03 11:39:16 +00:00
|
|
|
|
|
|
|
|
|
|
|
@bp.before_request
|
|
|
|
@login_required
|
|
|
|
@permission_required(Permission.CONTRIBUTE)
|
|
|
|
def before_request():
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
2022-10-26 08:23:22 +00:00
|
|
|
@bp.route('')
|
2022-09-02 11:02:04 +00:00
|
|
|
def contributions():
|
2022-10-26 08:23:22 +00:00
|
|
|
pass
|
2022-10-25 11:07:10 +00:00
|
|
|
|
2022-10-26 08:23:22 +00:00
|
|
|
|
|
|
|
@bp.route('/tesseract-ocr-pipeline-models', methods=['GET', 'POST'])
|
|
|
|
def tesseract_ocr_pipeline_models():
|
|
|
|
form = ContributionForm(
|
|
|
|
prefix='contribute-tesseract-ocr-pipeline-model-form'
|
|
|
|
)
|
2022-10-25 11:07:10 +00:00
|
|
|
if form.is_submitted():
|
|
|
|
if not form.validate():
|
|
|
|
response = {'errors': form.errors}
|
|
|
|
return response, 400
|
|
|
|
try:
|
2022-10-26 08:23:22 +00:00
|
|
|
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
|
|
|
|
)
|
2022-10-25 11:07:10 +00:00
|
|
|
except OSError:
|
|
|
|
abort(500)
|
|
|
|
db.session.commit()
|
2022-10-26 08:23:22 +00:00
|
|
|
message = Markup(f'Model "{tesseract_ocr_model.title}" created')
|
|
|
|
flash(message)
|
|
|
|
return {}, 201, {'Location': url_for('contributions.contributions')}
|
2022-10-02 21:49:14 +00:00
|
|
|
return render_template(
|
|
|
|
'contributions/contribute.html.j2',
|
|
|
|
form=form,
|
|
|
|
title='Contribution'
|
|
|
|
)
|