mirror of
				https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
				synced 2025-10-31 02:32:45 +00:00 
			
		
		
		
	Allow multiple file upload and add title
This commit is contained in:
		| @@ -1,35 +1,31 @@ | ||||
| from flask_wtf import FlaskForm | ||||
| from flask_wtf.file import FileAllowed, FileRequired | ||||
| from wtforms import FileField, SelectField, StringField, SubmitField | ||||
| from wtforms import MultipleFileField, SelectField, StringField, SubmitField | ||||
| from wtforms.validators import DataRequired, Length | ||||
|  | ||||
|  | ||||
| class OCRJobForm(FlaskForm): | ||||
| class CreateOCRJobForm(FlaskForm): | ||||
|     description = StringField( | ||||
|         'Description', | ||||
|         validators=[DataRequired(), Length(1, 64)] | ||||
|     ) | ||||
|     file = FileField( | ||||
|         'File', | ||||
|         validators=[ | ||||
|             FileAllowed(['pdf', 'tif', 'tiff']), | ||||
|             FileRequired() | ||||
|         ] | ||||
|     ) | ||||
|     files = MultipleFileField('Files', validators=[DataRequired()]) | ||||
|     language = SelectField( | ||||
|         'Language', | ||||
|         choices=[ | ||||
|             ('', 'Choose your option'), | ||||
|             ('eng', 'English'), | ||||
|             ('enm', 'English, Middle (1100-1500)'), | ||||
|             ('fra', 'French'), | ||||
|             ('frm', 'French, Middle (ca. 1400-1600)'), | ||||
|             ('deu', 'German'), | ||||
|             ('frk', 'German Fraktur'), | ||||
|             ('ita', 'Italian'), | ||||
|             ('por', 'Portuguese'), | ||||
|             ('spa', 'Spanish; Castilian') | ||||
|         ], | ||||
|         choices=[('', 'Choose your option'), | ||||
|                  ('eng', 'English'), | ||||
|                  ('enm', 'English, Middle (1100-1500)'), | ||||
|                  ('fra', 'French'), | ||||
|                  ('frm', 'French, Middle (ca. 1400-1600)'), | ||||
|                  ('deu', 'German'), | ||||
|                  ('frk', 'German Fraktur'), | ||||
|                  ('ita', 'Italian'), | ||||
|                  ('por', 'Portuguese'), | ||||
|                  ('spa', 'Spanish; Castilian') | ||||
|                  ], | ||||
|         validators=[DataRequired()] | ||||
|     ) | ||||
|     submit = SubmitField('Submit') | ||||
|     submit = SubmitField('Create OCR job') | ||||
|     title = StringField( | ||||
|         'Title', | ||||
|         validators=[DataRequired(), Length(1, 32)] | ||||
|     ) | ||||
|   | ||||
| @@ -2,7 +2,7 @@ from datetime import datetime | ||||
| from flask import current_app, flash, redirect, render_template, url_for | ||||
| from . import services | ||||
| from flask_login import current_user, login_required | ||||
| from .forms import OCRJobForm | ||||
| from .forms import CreateOCRJobForm | ||||
| from ..import swarm | ||||
| from threading import Thread | ||||
| import hashlib | ||||
| @@ -12,8 +12,8 @@ import os | ||||
| @services.route('/ocr', methods=['GET', 'POST']) | ||||
| @login_required | ||||
| def ocr(): | ||||
|     ocr_job_form = OCRJobForm() | ||||
|     if ocr_job_form.validate_on_submit(): | ||||
|     create_ocr_job_form = CreateOCRJobForm() | ||||
|     if create_ocr_job_form.validate_on_submit(): | ||||
|         app = current_app._get_current_object() | ||||
|         id = hashlib.md5( | ||||
|             (current_user.username + '_' + datetime.now().isoformat()).encode() | ||||
| @@ -27,7 +27,7 @@ def ocr(): | ||||
|                'requested_cpus': 2, | ||||
|                'requested_memory': 2048, | ||||
|                'service': 'ocr', | ||||
|                'service_args': {'lang': ocr_job_form.language.data, | ||||
|                'service_args': {'lang': create_ocr_job_form.language.data, | ||||
|                                 'version': 'latest' | ||||
|                                 }, | ||||
|                'status': 'queued' | ||||
| @@ -39,8 +39,8 @@ def ocr(): | ||||
|         except OSError: | ||||
|             flash('OSError!') | ||||
|         else: | ||||
|             file = ocr_job_form.file.data | ||||
|             file.save(os.path.join(dir, file.filename)) | ||||
|             for file in create_ocr_job_form.files.data: | ||||
|                 file.save(os.path.join(dir, file.filename)) | ||||
|             ''' | ||||
|             ' TODO: Let the scheduler run this job in the background. | ||||
|             ' | ||||
| @@ -55,5 +55,5 @@ def ocr(): | ||||
|     return render_template( | ||||
|         'services/ocr.html.j2', | ||||
|         title='Optical Character Recognition', | ||||
|         ocr_job_form=ocr_job_form | ||||
|         create_ocr_job_form=create_ocr_job_form | ||||
|     ) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user