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
|
2019-08-01 06:22:17 +00:00
|
|
|
from wtforms.validators import DataRequired, Length
|
2019-07-19 11:28:17 +00:00
|
|
|
|
|
|
|
|
2019-08-09 09:48:43 +00:00
|
|
|
class NewNLPJobForm(FlaskForm):
|
2019-08-01 06:22:17 +00:00
|
|
|
description = StringField(
|
|
|
|
'Description',
|
2019-08-09 09:48:43 +00:00
|
|
|
validators=[DataRequired(), Length(1, 255)]
|
2019-08-01 06:22:17 +00:00
|
|
|
)
|
2019-08-01 10:16:31 +00:00
|
|
|
files = MultipleFileField('Files', validators=[DataRequired()])
|
2019-08-01 06:22:17 +00:00
|
|
|
language = SelectField(
|
|
|
|
'Language',
|
2019-08-01 10:16:31 +00:00
|
|
|
choices=[('', 'Choose your option'),
|
2019-08-09 09:48:43 +00:00
|
|
|
('en', 'English'),
|
|
|
|
('fr', 'French'),
|
|
|
|
('de', 'German'),
|
|
|
|
('it', 'Italian'),
|
|
|
|
('pt', 'Portuguese'),
|
2019-09-11 13:40:37 +00:00
|
|
|
('es', 'Spanish')],
|
2019-08-01 06:22:17 +00:00
|
|
|
validators=[DataRequired()]
|
|
|
|
)
|
2019-08-05 13:35:18 +00:00
|
|
|
submit = SubmitField('Submit')
|
2019-08-01 10:16:31 +00:00
|
|
|
title = StringField(
|
|
|
|
'Title',
|
|
|
|
validators=[DataRequired(), Length(1, 32)]
|
|
|
|
)
|
2019-08-05 10:25:51 +00:00
|
|
|
version = SelectField(
|
|
|
|
'Version',
|
|
|
|
choices=[('', 'Choose your option'),
|
2019-09-11 13:40:37 +00:00
|
|
|
('latest', 'Latest (2.1.0)'),
|
|
|
|
('2.1.0', '2.1.0')],
|
2019-08-05 10:25:51 +00:00
|
|
|
validators=[DataRequired()]
|
|
|
|
)
|
2019-08-01 12:01:22 +00:00
|
|
|
|
|
|
|
def validate_files(form, field):
|
|
|
|
for file in field.data:
|
2019-08-09 09:48:43 +00:00
|
|
|
if not file.filename.lower().endswith('.txt'):
|
2019-08-01 12:01:22 +00:00
|
|
|
raise ValidationError(
|
|
|
|
'File does not have an approved extension: '
|
2019-08-09 09:48:43 +00:00
|
|
|
'.txt'
|
2019-08-01 12:01:22 +00:00
|
|
|
)
|
2019-08-05 06:36:29 +00:00
|
|
|
|
|
|
|
|
2019-08-09 09:48:43 +00:00
|
|
|
class NewOCRJobForm(FlaskForm):
|
2019-08-05 06:36:29 +00:00
|
|
|
description = StringField(
|
|
|
|
'Description',
|
2019-08-09 09:48:43 +00:00
|
|
|
validators=[DataRequired(), Length(1, 255)]
|
2019-08-05 06:36:29 +00:00
|
|
|
)
|
|
|
|
files = MultipleFileField('Files', validators=[DataRequired()])
|
|
|
|
language = SelectField(
|
|
|
|
'Language',
|
|
|
|
choices=[('', 'Choose your option'),
|
2019-08-09 09:48:43 +00:00
|
|
|
('eng', 'English'),
|
|
|
|
('enm', 'English, Middle (1100-1500)'),
|
|
|
|
('fra', 'French'),
|
|
|
|
('frm', 'French, Middle (ca. 1400-1600)'),
|
|
|
|
('deu', 'German'),
|
|
|
|
('frk', 'German Fraktur'),
|
|
|
|
('ita', 'Italian'),
|
|
|
|
('por', 'Portuguese'),
|
2019-09-11 13:40:37 +00:00
|
|
|
('spa', 'Spanish; Castilian')],
|
2019-08-05 06:36:29 +00:00
|
|
|
validators=[DataRequired()]
|
|
|
|
)
|
2019-08-05 13:35:18 +00:00
|
|
|
submit = SubmitField('Submit')
|
2019-08-05 06:36:29 +00:00
|
|
|
title = StringField(
|
|
|
|
'Title',
|
|
|
|
validators=[DataRequired(), Length(1, 32)]
|
|
|
|
)
|
2019-08-05 10:25:51 +00:00
|
|
|
version = SelectField(
|
|
|
|
'Version',
|
|
|
|
choices=[('', 'Choose your option'),
|
2019-09-11 13:40:37 +00:00
|
|
|
('latest', 'Latest')],
|
2019-08-05 10:25:51 +00:00
|
|
|
validators=[DataRequired()]
|
|
|
|
)
|
2019-08-05 06:36:29 +00:00
|
|
|
|
|
|
|
def validate_files(form, field):
|
|
|
|
for file in field.data:
|
2019-08-09 09:48:43 +00:00
|
|
|
if not file.filename.lower().endswith(('.pdf', '.tif', '.tiff')):
|
2019-08-05 06:36:29 +00:00
|
|
|
raise ValidationError(
|
|
|
|
'File does not have an approved extension: '
|
2019-08-09 09:48:43 +00:00
|
|
|
'.pdf | .tif | .tiff'
|
2019-08-05 06:36:29 +00:00
|
|
|
)
|