diff --git a/app/forms/forum.py b/app/forms/forum.py index 30bcd90..fbcf5c4 100644 --- a/app/forms/forum.py +++ b/app/forms/forum.py @@ -2,25 +2,45 @@ from flask_wtf import FlaskForm from wtforms import StringField, SubmitField, TextAreaField, MultipleFileField from wtforms.validators import InputRequired, Length import app.utils.validators as vd +from app.utils.antibot_field import AntibotField class CommentForm(FlaskForm): - message = TextAreaField('Message', validators=[InputRequired()]) - attachments = MultipleFileField('Pièces-jointes', - validators=[vd.file.optional, vd.file.count, vd.file.extension, - vd.file.size, vd.file.namelength]) + message = TextAreaField( + 'Message', + validators=[InputRequired()]) + + attachments = MultipleFileField( + 'Pièces-jointes', + validators=[ + vd.file.optional, + vd.file.count, + vd.file.extension, + vd.file.size, + vd.file.namelength + ]) + submit = SubmitField('Commenter') class AnonymousCommentForm(CommentForm): - pseudo = StringField('Pseudo', + pseudo = StringField( + 'Pseudo', validators=[InputRequired(), vd.name.valid, vd.name.available]) + ab = AntibotField() class CommentEditForm(CommentForm): # Boolean fields to remove files are added dynamically - attachments = MultipleFileField('Ajouter des pièces jointes', - validators=[vd.file.optional, vd.file.count, vd.file.extension, - vd.file.size, vd.file.namelength]) + attachments = MultipleFileField( + 'Ajouter des pièces jointes', + validators=[ + vd.file.optional, + vd.file.count, + vd.file.extension, + vd.file.size, + vd.file.namelength + ]) + submit = SubmitField('Modifier') @@ -29,10 +49,12 @@ class AnonymousCommentEditForm(CommentEditForm, AnonymousCommentForm): class TopicCreationForm(CommentForm): - title = StringField('Nom du sujet', + title = StringField( + 'Nom du sujet', validators=[InputRequired(), Length(min=3, max=128)]) + submit = SubmitField('Créer le sujet') class AnonymousTopicCreationForm(TopicCreationForm, AnonymousCommentForm): - pass + ab = AntibotField() diff --git a/app/static/css/form.css b/app/static/css/form.css index 7fe9dfb..bab32f3 100644 --- a/app/static/css/form.css +++ b/app/static/css/form.css @@ -102,6 +102,10 @@ /*width: 20%;*/ } +.form input.abfield { + display: none; +} + .form form .msgerror { color: var(--error); font-weight: 400; diff --git a/app/templates/forum/forum.html b/app/templates/forum/forum.html index 8a33226..0c6e440 100644 --- a/app/templates/forum/forum.html +++ b/app/templates/forum/forum.html @@ -62,6 +62,7 @@ {{ error }} {% endfor %} + {{ form.ab }} {% endif %}