forms.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. # **************************************************************************
  4. # Copyright © 2016 jianglin
  5. # File Name: forms.py
  6. # Author: jianglin
  7. # Email: xiyang0807@gmail.com
  8. # Created: 2016-12-18 18:49:00 (CST)
  9. # Last Update:星期四 2016-12-29 22:45:52 (CST)
  10. # By:
  11. # Description:
  12. # **************************************************************************
  13. from flask import request, render_template, redirect, url_for
  14. from flask_wtf import Form
  15. from wtforms import (StringField, TextAreaField, SelectField, RadioField)
  16. from wtforms.validators import DataRequired, Length
  17. from flask_babelex import lazy_gettext as _
  18. from .models import Topic
  19. def error_callback():
  20. return redirect(url_for('topic.ask'))
  21. def collect_error_callback():
  22. return redirect(url_for('topic.collectlist'))
  23. class TopicForm(Form):
  24. title = StringField(_('Title:'), [DataRequired(), Length(min=4, max=36)])
  25. content = TextAreaField(_('Content:'), [DataRequired(), Length(min=6)])
  26. category = SelectField(_('Category:'), coerce=int)
  27. tags = StringField(_('Tags:'), [DataRequired(), Length(min=2, max=36)])
  28. content_type = SelectField(
  29. _('ContentType'), choices=Topic.CONTENT_TYPE, coerce=str)
  30. class ReplyForm(Form):
  31. content = TextAreaField(_('Content:'), [DataRequired()])
  32. class CollectForm(Form):
  33. name = StringField(_('Name:'), [DataRequired()])
  34. description = TextAreaField(_('Description:'))
  35. private = RadioField(
  36. 'Private:', choices=[(0, 'privacy'), (1, 'public')], coerce=int)