Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
nopaque
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Monitor
Service Desk
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
SFB 1288 - INF
nopaque
Commits
df7d618b
Commit
df7d618b
authored
5 years ago
by
Patrick Jentsch
Browse files
Options
Downloads
Patches
Plain Diff
Add file type validation
parent
c958edba
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
app/main/forms.py
+7
-5
7 additions, 5 deletions
app/main/forms.py
app/services/forms.py
+9
-1
9 additions, 1 deletion
app/services/forms.py
with
16 additions
and
6 deletions
app/main/forms.py
+
7
−
5
View file @
df7d618b
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
'
)
This diff is collapsed.
Click to expand it.
app/services/forms.py
+
9
−
1
View file @
df7d618b
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
'
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment