nopaque/app/services/forms.py

40 lines
1.4 KiB
Python
Raw Normal View History

2019-07-19 11:28:17 +00:00
from flask_wtf import FlaskForm
2019-08-01 12:01:22 +00:00
from wtforms import MultipleFileField, SelectField, StringField, SubmitField, ValidationError
from wtforms.validators import DataRequired, Length
2019-07-19 11:28:17 +00:00
class CreateOCRJobForm(FlaskForm):
description = StringField(
'Description',
validators=[DataRequired(), Length(1, 64)]
)
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')
],
validators=[DataRequired()]
)
submit = SubmitField('Create OCR job')
title = StringField(
'Title',
validators=[DataRequired(), Length(1, 32)]
)
2019-08-01 12:01:22 +00:00
def validate_files(form, field):
for file in field.data:
if not file.filename.lower().endswith(('.pdf', '.tif', '.tiff')):
raise ValidationError(
'File does not have an approved extension: '
'.pdf | .tif | .tiff'
)