mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2024-12-25 10:54:18 +00:00
Remove implementation of FileSize validator
This commit is contained in:
parent
991810cff5
commit
4a29a52f2a
@ -1,14 +0,0 @@
|
|||||||
from wtforms.validators import ValidationError
|
|
||||||
|
|
||||||
|
|
||||||
def FileSize(max_size_mb):
|
|
||||||
max_size_b = max_size_mb * 1024 * 1024
|
|
||||||
|
|
||||||
def file_length_check(form, field):
|
|
||||||
if len(field.data.read()) >= max_size_b:
|
|
||||||
raise ValidationError(
|
|
||||||
f'File size must be less or equal than {max_size_mb} MB'
|
|
||||||
)
|
|
||||||
field.data.seek(0)
|
|
||||||
|
|
||||||
return file_length_check
|
|
@ -1,5 +1,5 @@
|
|||||||
from flask_wtf import FlaskForm
|
from flask_wtf import FlaskForm
|
||||||
from flask_wtf.file import FileField, FileRequired
|
from flask_wtf.file import FileField, FileRequired, FileSize
|
||||||
from wtforms import (
|
from wtforms import (
|
||||||
PasswordField,
|
PasswordField,
|
||||||
SelectField,
|
SelectField,
|
||||||
@ -16,7 +16,6 @@ from wtforms.validators import (
|
|||||||
Regexp
|
Regexp
|
||||||
)
|
)
|
||||||
from app.models import User, UserSettingJobStatusMailNotificationLevel
|
from app.models import User, UserSettingJobStatusMailNotificationLevel
|
||||||
from app.extensions.wtforms_extras.validators import FileSize
|
|
||||||
|
|
||||||
|
|
||||||
class UpdateAccountInformationForm(FlaskForm):
|
class UpdateAccountInformationForm(FlaskForm):
|
||||||
@ -99,7 +98,7 @@ class UpdateProfileInformationForm(FlaskForm):
|
|||||||
|
|
||||||
|
|
||||||
class UpdateAvatarForm(FlaskForm):
|
class UpdateAvatarForm(FlaskForm):
|
||||||
avatar = FileField('File', validators=[FileRequired(), FileSize(2)])
|
avatar = FileField('File', validators=[FileRequired(), FileSize(2_000_000)])
|
||||||
submit = SubmitField()
|
submit = SubmitField()
|
||||||
|
|
||||||
def validate_avatar(self, field):
|
def validate_avatar(self, field):
|
||||||
|
Loading…
Reference in New Issue
Block a user