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
|
2019-09-08 14:34:51 +02:00
|
|
|
|
2019-12-03 20:32:01 +01:00
|
|
|
class CommentForm(FlaskForm):
|
2020-08-05 23:26:36 +02:00
|
|
|
message = TextAreaField('Message', validators=[InputRequired()])
|
2020-08-01 21:26:06 +02:00
|
|
|
attachments = MultipleFileField('Pièces-jointes',
|
|
|
|
validators=[vd.file.optional, vd.file.count, vd.file.extension,
|
2020-08-02 15:03:08 +02:00
|
|
|
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):
|
|
|
|
pseudo = StringField('Pseudo',
|
2020-08-06 00:04:47 +02:00
|
|
|
validators=[InputRequired(), vd.name.valid, vd.name.available])
|
|
|
|
|
2020-08-01 17:25:08 +02:00
|
|
|
|
|
|
|
class CommentEditForm(CommentForm):
|
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):
|
|
|
|
title = StringField('Nom du sujet',
|
2020-10-30 09:36:21 +01:00
|
|
|
validators=[InputRequired(), Length(min=3, max=128)])
|
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):
|
|
|
|
pass
|