forms.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. # -*- coding: utf-8 -*-
  2. """
  3. flaskbb.forum.forms
  4. ~~~~~~~~~~~~~~~~~~~~
  5. It provides the forms that are needed for the forum views.
  6. :copyright: (c) 2013 by the FlaskBB Team.
  7. :license: BSD, see LICENSE for more details.
  8. """
  9. from flask.ext.wtf import Form, Required, TextAreaField, TextField
  10. from flaskbb.forum.models import Topic, Post
  11. class QuickreplyForm(Form):
  12. content = TextAreaField("Quickreply", validators=[
  13. Required(message="You cannot post a reply without content.")])
  14. def save(self, user, topic):
  15. post = Post(**self.data)
  16. return post.save(user=user, topic=topic)
  17. class ReplyForm(Form):
  18. content = TextAreaField("Content", validators=[
  19. Required(message="You cannot post a reply without content.")])
  20. def save(self, user, topic):
  21. post = Post(**self.data)
  22. return post.save(user=user, topic=topic)
  23. class NewTopicForm(ReplyForm):
  24. title = TextField("Topic Title", validators=[
  25. Required(message="A topic title is required")])
  26. content = TextAreaField("Content", validators=[
  27. Required(message="You cannot post a reply without content.")])
  28. def save(self, user, forum):
  29. topic = Topic(title=self.title.data)
  30. post = Post(content=self.content.data)
  31. return topic.save(user=user, forum=forum, post=post)