| | from flask_wtf import FlaskForm |
| | from wtforms import TextAreaField, MultipleFileField, StringField, SubmitField |
| | from wtforms.validators import Optional, Length |
| |
|
| | class PostForm(FlaskForm): |
| | nickname = StringField('Pseudo', validators=[Optional(), Length(max=50)]) |
| | content = TextAreaField('Message', validators=[Optional(), Length(max=2000)]) |
| | files = MultipleFileField('Fichiers', validators=[Optional()]) |
| | honeypot = StringField('Site Web', validators=[Optional()]) |
| | submit = SubmitField('Envoyer') |
| |
|
| | def validate(self, extra_validators=None): |
| | initial_validation = super(PostForm, self).validate(extra_validators) |
| | if not initial_validation: |
| | return False |
| | |
| | |
| | if not self.content.data and not self.files.data: |
| | |
| | has_files = False |
| | if self.files.data: |
| | for f in self.files.data: |
| | if f.filename: |
| | has_files = True |
| | break |
| | |
| | if not has_files and not self.content.data: |
| | self.content.errors.append('Vous devez fournir un message ou un fichier.') |
| | return False |
| | |
| | |
| | if self.honeypot.data: |
| | return False |
| | |
| | return True |
| |
|