nopaque/app/jobs/forms.py

89 lines
4.0 KiB
Python
Raw Normal View History

2019-07-19 11:28:17 +00:00
from flask_wtf import FlaskForm
2019-09-12 14:00:48 +00:00
from wtforms import (BooleanField, MultipleFileField, SelectField, StringField,
SubmitField, ValidationError)
from wtforms.validators import DataRequired, Length
2019-07-19 11:28:17 +00:00
2019-11-08 11:21:59 +00:00
class AddNLPJobForm(FlaskForm):
2019-09-12 09:12:59 +00:00
description = StringField('Description',
validators=[DataRequired(), Length(1, 255)])
files = MultipleFileField('Files', validators=[DataRequired()])
2019-09-12 09:12:59 +00:00
language = SelectField('Language',
choices=[('', 'Choose your option'),
('nl', 'Dutch'),
('en', 'English'),
('fr', 'French'),
('de', 'German'),
('el', 'Greek'),
('it', 'Italian'),
('pt', 'Portuguese'),
('es', 'Spanish')],
validators=[DataRequired()])
2019-10-30 13:26:13 +00:00
submit = SubmitField()
2019-09-12 09:12:59 +00:00
title = StringField('Title', validators=[DataRequired(), Length(1, 32)])
version = SelectField('Version',
2020-01-07 10:34:16 +00:00
choices=[('2.2.0', 'Latest (2.2.0)'),
2020-01-20 14:32:38 +00:00
('2.2.0', '2.2.0')],
2019-09-12 09:12:59 +00:00
validators=[DataRequired()])
2020-02-13 13:41:02 +00:00
check_encoding = BooleanField('Check encoding')
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(
2019-09-12 09:12:59 +00:00
'File does not have an approved extension: .txt'
2019-08-01 12:01:22 +00:00
)
2019-11-08 11:21:59 +00:00
class AddOCRJobForm(FlaskForm):
2019-09-12 14:00:48 +00:00
binarization = BooleanField('Binarazation')
2019-09-12 09:12:59 +00:00
description = StringField('Description',
validators=[DataRequired(), Length(1, 255)])
files = MultipleFileField('Files', validators=[DataRequired()])
2019-09-12 09:12:59 +00:00
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()])
2019-09-12 14:00:48 +00:00
split = BooleanField('Split')
2019-10-30 13:26:13 +00:00
submit = SubmitField()
2019-09-12 09:12:59 +00:00
title = StringField('Title', validators=[DataRequired(), Length(1, 32)])
version = SelectField('Version',
choices=[('latest', 'Latest')],
validators=[DataRequired()])
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')):
raise ValidationError(
'File does not have an approved extension: '
2019-08-09 09:48:43 +00:00
'.pdf | .tif | .tiff'
)
2020-01-07 12:03:42 +00:00
2020-02-07 14:21:59 +00:00
class AddSetupFilesJobForm(FlaskForm):
2020-01-07 13:39:01 +00:00
description = StringField('Description',
validators=[DataRequired(), Length(1, 255)])
submit = SubmitField()
title = StringField('Title', validators=[DataRequired(), Length(1, 32)])
2020-01-07 12:03:42 +00:00
files = MultipleFileField('Files', validators=[DataRequired()])
2020-01-07 13:39:01 +00:00
version = SelectField('Version',
choices=[('latest', 'Latest')],
validators=[DataRequired()])
2020-01-07 12:03:42 +00:00
2020-01-07 12:05:44 +00:00
def validate_files(form, field):
2020-01-07 12:03:42 +00:00
for file in field.data:
if not file.filename.lower().endswith(('.jpeg', '.jpg', '.png',
'.tiff', '.tif')):
raise ValidationError(
'File does not have an approved extension: '
'.jpeg | .jpg | .png | .tiff | .tif'
)