2023-03-14 10:13:35 +00:00
|
|
|
from flask import abort, flash, redirect, render_template, request, url_for
|
|
|
|
from flask_breadcrumbs import register_breadcrumb
|
|
|
|
from flask_login import current_user, login_required
|
|
|
|
from app import db
|
|
|
|
from app.models import TesseractOCRPipelineModel
|
|
|
|
from . import bp
|
|
|
|
from .forms import (
|
|
|
|
CreateTesseractOCRPipelineModelForm,
|
2023-03-31 07:14:21 +00:00
|
|
|
UpdateTesseractOCRPipelineModelForm
|
2023-03-14 10:13:35 +00:00
|
|
|
)
|
|
|
|
from .utils import (
|
|
|
|
tesseract_ocr_pipeline_model_dlc as tesseract_ocr_pipeline_model_dlc
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
@bp.route('/tesseract-ocr-pipeline-models')
|
|
|
|
@register_breadcrumb(bp, '.tesseract_ocr_pipeline_models', 'Tesseract OCR Pipeline Models')
|
|
|
|
@login_required
|
|
|
|
def tesseract_ocr_pipeline_models():
|
|
|
|
return render_template(
|
|
|
|
'contributions/tesseract_ocr_pipeline_models/tesseract_ocr_pipeline_models.html.j2',
|
|
|
|
title='Tesseract OCR Pipeline Models'
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
@bp.route('/tesseract-ocr-pipeline-models/create', methods=['GET', 'POST'])
|
|
|
|
@register_breadcrumb(bp, '.tesseract_ocr_pipeline_models.create', 'Create')
|
|
|
|
@login_required
|
|
|
|
def create_tesseract_ocr_pipeline_model():
|
2023-03-29 07:25:08 +00:00
|
|
|
form = CreateTesseractOCRPipelineModelForm()
|
2023-03-14 10:13:35 +00:00
|
|
|
if form.is_submitted():
|
|
|
|
if not form.validate():
|
|
|
|
return {'errors': form.errors}, 400
|
|
|
|
try:
|
|
|
|
topm = TesseractOCRPipelineModel.create(
|
|
|
|
form.tesseract_model_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,
|
|
|
|
is_public=False,
|
|
|
|
title=form.title.data,
|
|
|
|
version=form.version.data,
|
|
|
|
user=current_user
|
|
|
|
)
|
|
|
|
except OSError:
|
|
|
|
abort(500)
|
|
|
|
db.session.commit()
|
|
|
|
flash(f'Tesseract OCR Pipeline model "{topm.title}" created')
|
|
|
|
return {}, 201, {'Location': url_for('.tesseract_ocr_pipeline_models')}
|
|
|
|
return render_template(
|
|
|
|
'contributions/tesseract_ocr_pipeline_models/create_tesseract_ocr_pipeline_model.html.j2',
|
2023-03-28 12:19:37 +00:00
|
|
|
title='Create Tesseract OCR Pipeline Model',
|
|
|
|
form=form
|
2023-03-14 10:13:35 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
@bp.route('/tesseract-ocr-pipeline-models/<hashid:tesseract_ocr_pipeline_model_id>', methods=['GET', 'POST'])
|
|
|
|
@register_breadcrumb(bp, '.tesseract_ocr_pipeline_models.entity', '', dynamic_list_constructor=tesseract_ocr_pipeline_model_dlc)
|
|
|
|
@login_required
|
|
|
|
def tesseract_ocr_pipeline_model(tesseract_ocr_pipeline_model_id):
|
|
|
|
topm = TesseractOCRPipelineModel.query.get_or_404(tesseract_ocr_pipeline_model_id)
|
2023-03-31 07:14:21 +00:00
|
|
|
form = UpdateTesseractOCRPipelineModelForm(data=topm.to_json_serializeable())
|
2023-03-14 10:13:35 +00:00
|
|
|
if form.validate_on_submit():
|
|
|
|
form.populate_obj(topm)
|
|
|
|
if db.session.is_modified(topm):
|
|
|
|
flash(f'Tesseract OCR Pipeline model "{topm.title}" updated')
|
|
|
|
db.session.commit()
|
|
|
|
return redirect(url_for('.tesseract_ocr_pipeline_models'))
|
|
|
|
return render_template(
|
|
|
|
'contributions/tesseract_ocr_pipeline_models/tesseract_ocr_pipeline_model.html.j2',
|
2023-03-28 12:19:37 +00:00
|
|
|
title=f'{topm.title} {topm.version}',
|
2023-03-14 10:13:35 +00:00
|
|
|
form=form,
|
2023-03-28 12:19:37 +00:00
|
|
|
tesseract_ocr_pipeline_model=topm
|
2023-03-14 10:13:35 +00:00
|
|
|
)
|