attachments: fix #67
This commit is contained in:
parent
03c577316f
commit
a83cef5970
|
@ -8,7 +8,7 @@ class CommentForm(FlaskForm):
|
|||
message = TextAreaField('Message', validators=[DataRequired()])
|
||||
attachments = MultipleFileField('Pièces-jointes',
|
||||
validators=[vd.file.optional, vd.file.count, vd.file.extension,
|
||||
vd.file.size])
|
||||
vd.file.size, vd.file.namelength])
|
||||
submit = SubmitField('Commenter')
|
||||
preview = SubmitField('Prévisualiser')
|
||||
|
||||
|
|
|
@ -49,3 +49,13 @@ def size(form, files):
|
|||
else:
|
||||
if size > 500e3: # 500 ko per comment for a guest
|
||||
raise ValidationError("Fichiers trop lourds (max 500 ko)")
|
||||
|
||||
def namelength(form, files):
|
||||
errors = []
|
||||
for f in files.data:
|
||||
name = secure_filename(f.filename)
|
||||
if len(name) > 64:
|
||||
errors.append(f.filename)
|
||||
if len(errors) > 0:
|
||||
raise ValidationError(f"Noms trop longs, 64 caractères max " \
|
||||
f"({', '.join(errors)})")
|
||||
|
|
Loading…
Reference in New Issue