mirror of
				https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
				synced 2025-11-04 04:12:45 +00:00 
			
		
		
		
	Add file type validation
This commit is contained in:
		@@ -1,5 +1,5 @@
 | 
			
		||||
from flask_wtf import FlaskForm
 | 
			
		||||
from wtforms import MultipleFileField, StringField, SubmitField
 | 
			
		||||
from wtforms import MultipleFileField, StringField, SubmitField, ValidationError
 | 
			
		||||
from wtforms.validators import DataRequired, Length
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@@ -14,8 +14,10 @@ class CreateCorpusForm(FlaskForm):
 | 
			
		||||
        'Title',
 | 
			
		||||
        validators=[DataRequired(), Length(1, 32)]
 | 
			
		||||
    )
 | 
			
		||||
    '''
 | 
			
		||||
 | 
			
		||||
    def validate_files(form, field):
 | 
			
		||||
        for file in form.files.getlist[field.name]:
 | 
			
		||||
            if file.mimetype
 | 
			
		||||
    '''
 | 
			
		||||
        for file in field.data:
 | 
			
		||||
            if not file.filename.lower().endswith('.vrt'):
 | 
			
		||||
                raise ValidationError(
 | 
			
		||||
                    'File does not have an approved extension: .vrt'
 | 
			
		||||
                )
 | 
			
		||||
 
 | 
			
		||||
@@ -1,5 +1,5 @@
 | 
			
		||||
from flask_wtf import FlaskForm
 | 
			
		||||
from wtforms import MultipleFileField, SelectField, StringField, SubmitField
 | 
			
		||||
from wtforms import MultipleFileField, SelectField, StringField, SubmitField, ValidationError
 | 
			
		||||
from wtforms.validators import DataRequired, Length
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@@ -29,3 +29,11 @@ class CreateOCRJobForm(FlaskForm):
 | 
			
		||||
        'Title',
 | 
			
		||||
        validators=[DataRequired(), Length(1, 32)]
 | 
			
		||||
    )
 | 
			
		||||
 | 
			
		||||
    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'
 | 
			
		||||
                )
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user