forms.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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) 2014 by the FlaskBB Team.
  7. :license: BSD, see LICENSE for more details.
  8. """
  9. from flask.ext.wtf import Form
  10. from wtforms import TextAreaField, TextField
  11. from wtforms.validators import Required
  12. from flaskbb.forum.models import Topic, Post, Report
  13. class QuickreplyForm(Form):
  14. content = TextAreaField("Quickreply", validators=[
  15. Required(message="You cannot post a reply without content.")])
  16. def save(self, user, topic):
  17. post = Post(**self.data)
  18. return post.save(user=user, topic=topic)
  19. class ReplyForm(Form):
  20. content = TextAreaField("Content", validators=[
  21. Required(message="You cannot post a reply without content.")])
  22. def save(self, user, topic):
  23. post = Post(**self.data)
  24. return post.save(user=user, topic=topic)
  25. class NewTopicForm(ReplyForm):
  26. title = TextField("Topic Title", validators=[
  27. Required(message="A topic title is required")])
  28. content = TextAreaField("Content", validators=[
  29. Required(message="You cannot post a reply without content.")])
  30. def save(self, user, forum):
  31. topic = Topic(title=self.title.data)
  32. post = Post(content=self.content.data)
  33. return topic.save(user=user, forum=forum, post=post)
  34. class ReportForm(Form):
  35. reason = TextAreaField("Reason", validators=[
  36. Required(message="Please insert a reason why you want to report this \
  37. post")
  38. ])
  39. def save(self, user, post):
  40. report = Report(**self.data)
  41. return report.save(user, post)