mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2025-06-12 00:50:40 +00:00
fix model contribution.
This commit is contained in:
@ -1,4 +1,5 @@
|
||||
from flask_wtf import FlaskForm
|
||||
from flask_wtf.file import FileField, FileRequired
|
||||
from wtforms import (
|
||||
BooleanField,
|
||||
PasswordField,
|
||||
@ -70,6 +71,12 @@ class ContributionForm(FlaskForm):
|
||||
validators=[InputRequired()]
|
||||
)
|
||||
|
||||
# file upload
|
||||
file = FileField(
|
||||
'File',
|
||||
validators=[FileRequired()]
|
||||
)
|
||||
|
||||
submit = SubmitField()
|
||||
|
||||
|
||||
|
@ -1,9 +1,11 @@
|
||||
from flask import render_template
|
||||
from flask_login import login_required
|
||||
from apifairy import authenticate
|
||||
from flask import render_template, flash, abort
|
||||
from flask_login import login_required, current_user
|
||||
from app.decorators import permission_required
|
||||
from app.models import Permission
|
||||
from app.models import Permission, TesseractOCRModel, JobStatus
|
||||
from . import bp
|
||||
from .forms import ContributionForm
|
||||
from .. import db
|
||||
|
||||
|
||||
@bp.before_request
|
||||
@ -14,8 +16,55 @@ def before_request():
|
||||
|
||||
|
||||
@bp.route('', methods=['GET', 'POST'])
|
||||
@login_required
|
||||
def contributions():
|
||||
form = ContributionForm(prefix='contribution-form')
|
||||
|
||||
# Is the form submitted?
|
||||
if form.is_submitted():
|
||||
# Are their any false inputs?
|
||||
if not form.validate():
|
||||
response = {'errors': form.errors}
|
||||
return response, 400
|
||||
|
||||
|
||||
# At this point we can be sure that the form data is okay
|
||||
# example
|
||||
# compatible_service_versions = ['0.1.0', '0.1.1']
|
||||
|
||||
|
||||
compatible_service_versions=form.compatible_service_versions.data
|
||||
description=form.description
|
||||
publisher=form.publisher
|
||||
publisher_url=form.publisher_url
|
||||
publishing_url=form.publishing_url
|
||||
publishing_year=form.publishing_year
|
||||
shared=False
|
||||
title=form.title
|
||||
version=form.version
|
||||
|
||||
|
||||
try:
|
||||
TesseractOCRModel.create(form.file.data,
|
||||
compatible_service_versions,
|
||||
description,
|
||||
publisher,
|
||||
publisher_url,
|
||||
publishing_url,
|
||||
publishing_year,
|
||||
shared,
|
||||
title,
|
||||
version)
|
||||
|
||||
except OSError:
|
||||
abort(500)
|
||||
# job.status = JobStatus.SUBMITTED
|
||||
db.session.commit()
|
||||
# message = Markup(f'Job "<a href="{job.url}">{job.title}</a>" created')
|
||||
flash("Model has been added.")
|
||||
return {}, 201, {'message': 'Model has been created'}
|
||||
|
||||
|
||||
return render_template(
|
||||
'contributions/contribute.html.j2',
|
||||
form=form,
|
||||
|
Reference in New Issue
Block a user