mirror of
				https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
				synced 2025-11-04 04:12:45 +00:00 
			
		
		
		
	Move route, cleanup and first fixes
This commit is contained in:
		@@ -1,11 +1,10 @@
 | 
				
			|||||||
from apifairy import authenticate
 | 
					from flask import abort, flash, Markup, render_template, url_for
 | 
				
			||||||
from flask import render_template, flash, abort
 | 
					from flask_login import login_required
 | 
				
			||||||
from flask_login import login_required, current_user
 | 
					from app import db
 | 
				
			||||||
from app.decorators import permission_required
 | 
					from app.decorators import permission_required
 | 
				
			||||||
from app.models import Permission, TesseractOCRModel, JobStatus
 | 
					from app.models import TesseractOCRModel, Permission
 | 
				
			||||||
from . import bp
 | 
					from . import bp
 | 
				
			||||||
from .forms import ContributionForm
 | 
					from .forms import ContributionForm
 | 
				
			||||||
from .. import db
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@bp.before_request
 | 
					@bp.before_request
 | 
				
			||||||
@@ -15,56 +14,39 @@ def before_request():
 | 
				
			|||||||
    pass
 | 
					    pass
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@bp.route('', methods=['GET', 'POST'])
 | 
					@bp.route('')
 | 
				
			||||||
@login_required
 | 
					 | 
				
			||||||
def contributions():
 | 
					def contributions():
 | 
				
			||||||
    form = ContributionForm(prefix='contribution-form')
 | 
					    pass
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    # Is the form submitted?
 | 
					
 | 
				
			||||||
 | 
					@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 form.is_submitted():
 | 
				
			||||||
        # Are their any false inputs?
 | 
					 | 
				
			||||||
        if not form.validate():
 | 
					        if not form.validate():
 | 
				
			||||||
            response = {'errors': form.errors}
 | 
					            response = {'errors': form.errors}
 | 
				
			||||||
            return response, 400
 | 
					            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:
 | 
					        try:
 | 
				
			||||||
            TesseractOCRModel.create(form.file.data,
 | 
					            tesseract_ocr_model = TesseractOCRModel.create(
 | 
				
			||||||
                                     compatible_service_versions,
 | 
					                form.file.data,
 | 
				
			||||||
                                     description,
 | 
					                compatible_service_versions=form.compatible_service_versions.data,
 | 
				
			||||||
                                     publisher,
 | 
					                description=form.description.data,
 | 
				
			||||||
                                     publisher_url,
 | 
					                publisher=form.publisher.data,
 | 
				
			||||||
                                     publishing_url,
 | 
					                publisher_url=form.publisher_url.data,
 | 
				
			||||||
                                     publishing_year,
 | 
					                publishing_url=form.publishing_url.data,
 | 
				
			||||||
                                     shared,
 | 
					                publishing_year=form.publishing_year.data,
 | 
				
			||||||
                                     title,
 | 
					                shared=form.shared.data,
 | 
				
			||||||
                                     version)
 | 
					                title=form.title.data,
 | 
				
			||||||
 | 
					                version=form.version.data
 | 
				
			||||||
 | 
					            )
 | 
				
			||||||
        except OSError:
 | 
					        except OSError:
 | 
				
			||||||
            abort(500)
 | 
					            abort(500)
 | 
				
			||||||
        # job.status = JobStatus.SUBMITTED
 | 
					 | 
				
			||||||
        db.session.commit()
 | 
					        db.session.commit()
 | 
				
			||||||
        # message = Markup(f'Job "<a href="{job.url}">{job.title}</a>" created')
 | 
					        message = Markup(f'Model "{tesseract_ocr_model.title}" created')
 | 
				
			||||||
        flash("Model has been added.")
 | 
					        flash(message)
 | 
				
			||||||
        return {}, 201, {'message': 'Model has been created'}
 | 
					        return {}, 201, {'Location': url_for('contributions.contributions')}
 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    return render_template(
 | 
					    return render_template(
 | 
				
			||||||
        'contributions/contribute.html.j2',
 | 
					        'contributions/contribute.html.j2',
 | 
				
			||||||
        form=form,
 | 
					        form=form,
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user