forms.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435
  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-18 19:44:27 (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
  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. class TopicForm(Form):
  22. title = StringField(_('Title:'), [DataRequired(), Length(min=4, max=36)])
  23. content = TextAreaField(_('Content:'), [DataRequired(), Length(min=6)])
  24. category = SelectField(_('Category:'), coerce=int)
  25. tags = StringField(_('Tags:'), [DataRequired(), Length(min=2, max=36)])
  26. content_type = SelectField(
  27. _('ContentType'), choices=Topic.CONTENT_TYPE, coerce=str)
  28. class ReplyForm(Form):
  29. content = TextAreaField(_('Content:'), [DataRequired()])