2019-09-08 14:34:51 +02:00
|
|
|
from flask_wtf import FlaskForm
|
2020-08-05 22:52:56 +02:00
|
|
|
from wtforms import StringField, SubmitField, TextAreaField, MultipleFileField
|
2020-08-05 23:26:36 +02:00
|
|
|
from wtforms.validators import InputRequired, Length
|
2020-07-17 23:49:04 +02:00
|
|
|
import app.utils.validators as vd
|
2021-07-10 12:29:52 +02:00
|
|
|
from app.utils.antibot_field import AntibotField
|
2019-09-08 14:34:51 +02:00
|
|
|
|
2019-12-03 20:32:01 +01:00
|
|
|
class CommentForm(FlaskForm):
|
2021-07-10 12:29:52 +02:00
|
|
|
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
|
|
|
|
])
|
|
|
|
|
2019-12-03 20:32:01 +01:00
|
|
|
submit = SubmitField('Commenter')
|
2020-07-17 23:49:04 +02:00
|
|
|
|
2020-08-06 00:04:47 +02:00
|
|
|
|
2020-07-17 23:49:04 +02:00
|
|
|
class AnonymousCommentForm(CommentForm):
|
2021-07-10 12:29:52 +02:00
|
|
|
pseudo = StringField(
|
|
|
|
'Pseudo',
|
2020-08-06 00:04:47 +02:00
|
|
|
validators=[InputRequired(), vd.name.valid, vd.name.available])
|
|
|
|
|
2021-07-10 12:29:52 +02:00
|
|
|
ab = AntibotField()
|
2020-08-01 17:25:08 +02:00
|
|
|
|
2021-07-12 19:06:23 +02:00
|
|
|
|
2020-08-01 17:25:08 +02:00
|
|
|
class CommentEditForm(CommentForm):
|
2021-07-08 16:47:39 +02:00
|
|
|
# Boolean fields to remove files are added dynamically
|
2021-07-10 12:29:52 +02:00
|
|
|
attachments = MultipleFileField(
|
|
|
|
'Ajouter des pièces jointes',
|
|
|
|
validators=[
|
|
|
|
vd.file.optional,
|
|
|
|
vd.file.count,
|
|
|
|
vd.file.extension,
|
|
|
|
vd.file.size,
|
|
|
|
vd.file.namelength
|
|
|
|
])
|
|
|
|
|
2020-08-01 21:47:25 +02:00
|
|
|
submit = SubmitField('Modifier')
|
2020-08-01 17:25:08 +02:00
|
|
|
|
2020-08-06 00:04:47 +02:00
|
|
|
|
2020-08-01 21:54:21 +02:00
|
|
|
class AnonymousCommentEditForm(CommentEditForm, AnonymousCommentForm):
|
2020-08-01 21:47:25 +02:00
|
|
|
pass
|
|
|
|
|
2020-08-01 21:26:06 +02:00
|
|
|
|
|
|
|
class TopicCreationForm(CommentForm):
|
2021-07-10 12:29:52 +02:00
|
|
|
title = StringField(
|
|
|
|
'Nom du sujet',
|
2020-10-30 09:36:21 +01:00
|
|
|
validators=[InputRequired(), Length(min=3, max=128)])
|
2021-07-10 12:29:52 +02:00
|
|
|
|
2020-08-01 21:26:06 +02:00
|
|
|
submit = SubmitField('Créer le sujet')
|
|
|
|
|
2020-08-06 00:04:47 +02:00
|
|
|
|
2020-08-01 21:26:06 +02:00
|
|
|
class AnonymousTopicCreationForm(TopicCreationForm, AnonymousCommentForm):
|
2021-07-10 12:29:52 +02:00
|
|
|
ab = AntibotField()
|
2021-07-12 19:06:23 +02:00
|
|
|
|
|
|
|
|
|
|
|
class TopicEditForm(CommentEditForm):
|
|
|
|
title = StringField(
|
|
|
|
'Nom du sujet',
|
|
|
|
validators=[InputRequired(), Length(min=3, max=128)])
|
|
|
|
|
|
|
|
submit = SubmitField('Modifier le sujet')
|