nopaque/app/contributions/tesseract_ocr_pipeline_models/forms.py

40 lines
1.6 KiB
Python
Raw Normal View History

2023-03-14 10:13:35 +00:00
from flask_wtf.file import FileField, FileRequired
from wtforms import ValidationError
from app.services import SERVICES
2023-03-31 07:14:21 +00:00
from ..forms import ContributionBaseForm, UpdateContributionBaseForm
2023-03-14 10:13:35 +00:00
class CreateTesseractOCRPipelineModelForm(ContributionBaseForm):
tesseract_model_file = FileField(
'File',
validators=[FileRequired()]
)
def validate_tesseract_model_file(self, field):
if not field.data.filename.lower().endswith('.traineddata'):
raise ValidationError('traineddata files only!')
def __init__(self, *args, **kwargs):
2023-03-31 07:14:21 +00:00
if 'prefix' not in kwargs:
kwargs['prefix'] = 'create-tesseract-ocr-pipeline-model-form'
2023-03-14 10:13:35 +00:00
service_manifest = SERVICES['tesseract-ocr-pipeline']
super().__init__(*args, **kwargs)
self.compatible_service_versions.choices = [('', 'Choose your option')]
self.compatible_service_versions.choices += [
(x, x) for x in service_manifest['versions'].keys()
]
self.compatible_service_versions.default = ''
2023-03-31 07:14:21 +00:00
class UpdateTesseractOCRPipelineModelForm(UpdateContributionBaseForm):
2023-03-14 10:13:35 +00:00
def __init__(self, *args, **kwargs):
2023-03-31 07:14:21 +00:00
if 'prefix' not in kwargs:
kwargs['prefix'] = 'edit-tesseract-ocr-pipeline-model-form'
2023-03-14 10:13:35 +00:00
service_manifest = SERVICES['tesseract-ocr-pipeline']
super().__init__(*args, **kwargs)
self.compatible_service_versions.choices = [('', 'Choose your option')]
self.compatible_service_versions.choices += [
(x, x) for x in service_manifest['versions'].keys()
]
self.compatible_service_versions.default = ''