75 lines
1.9 KiB
Python
75 lines
1.9 KiB
Python
from flask_wtf import FlaskForm
|
|
from wtforms import StringField, SubmitField, TextAreaField, MultipleFileField, SelectField
|
|
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
|
|
])
|
|
|
|
submit = SubmitField('Commenter')
|
|
|
|
|
|
class AnonymousCommentForm(CommentForm):
|
|
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
|
|
])
|
|
|
|
submit = SubmitField('Modifier')
|
|
|
|
|
|
class AnonymousCommentEditForm(CommentEditForm, AnonymousCommentForm):
|
|
pass
|
|
|
|
|
|
class TopicCreationForm(CommentForm):
|
|
title = StringField(
|
|
'Nom du sujet',
|
|
validators=[InputRequired(), Length(min=3, max=128)])
|
|
|
|
submit = SubmitField('Créer le sujet')
|
|
|
|
|
|
class AnonymousTopicCreationForm(TopicCreationForm, AnonymousCommentForm):
|
|
ab = AntibotField()
|
|
|
|
|
|
class TopicEditForm(CommentEditForm):
|
|
title = StringField(
|
|
'Nom du sujet',
|
|
validators=[InputRequired(), Length(min=3, max=128)])
|
|
|
|
# List of forums is generated at runtime
|
|
forum = SelectField(
|
|
'Forum',
|
|
validators=[InputRequired()])
|
|
|
|
submit = SubmitField('Modifier le sujet')
|