79 lines
2.0 KiB
Python
79 lines
2.0 KiB
Python
from flask_wtf import FlaskForm
|
||
from wtforms import StringField, SubmitField, TextAreaField, MultipleFileField, SelectField, DecimalField
|
||
from wtforms.validators import InputRequired, Length, Optional
|
||
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)])
|
||
|
||
summary = TextAreaField(
|
||
'Résumé',
|
||
validators=[Optional(), Length(min=3, max=128)])
|
||
|
||
thumbnail = DecimalField(
|
||
'N° de l’illustration',
|
||
validators=[Optional(), vd.attachment_exists])
|
||
|
||
submit = SubmitField('Créer le sujet')
|
||
|
||
|
||
class AnonymousTopicCreationForm(TopicCreationForm, AnonymousCommentForm):
|
||
ab = AntibotField()
|
||
|
||
|
||
class TopicEditForm(TopicCreationForm):
|
||
# List of forums is generated at runtime
|
||
forum = SelectField(
|
||
'Forum',
|
||
validators=[InputRequired()])
|
||
|
||
submit = SubmitField('Modifier le sujet')
|