forms.py 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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-20 22:13:24 (CST)
  9. # Last Update:星期六 2017-3-25 18:17:14 (CST)
  10. # By:
  11. # Description:
  12. # **************************************************************************
  13. from flask_wtf import Form
  14. from flask_babelex import lazy_gettext as _
  15. from wtforms import StringField, PasswordField, TextAreaField, SelectField
  16. from wtforms.validators import Length, DataRequired, EqualTo
  17. from flask_wtf.file import FileField, FileAllowed, FileRequired
  18. from forums.api.user.models import UserSetting
  19. from flask import redirect, url_for
  20. choices = UserSetting.STATUS
  21. timezone = UserSetting.TIMEZONE
  22. locale = UserSetting.LOCALE
  23. def error_callback(url):
  24. return lambda: redirect(url_for(url))
  25. class AvatarForm(Form):
  26. avatar = FileField(
  27. _('Upload Avatar:'),
  28. validators=[FileRequired(), FileAllowed(['jpg', 'png'],
  29. '上传文件只能为图片且图片格式为jpg,png')])
  30. class PrivacyForm(Form):
  31. online_status = SelectField(
  32. _('Login status:'), coerce=str, choices=choices)
  33. topic_list = SelectField(_('Topic List:'), coerce=str, choices=choices)
  34. rep_list = SelectField(_('Reply List:'), coerce=str, choices=choices)
  35. ntb_list = SelectField(_('Notebook List:'), coerce=str, choices=choices)
  36. collect_list = SelectField(_('Collect List:'), coerce=str, choices=choices)
  37. class ProfileForm(Form):
  38. introduce = TextAreaField(_('Introduce:'), [Length(max=256)])
  39. school = StringField(_('School:'), [Length(max=256)])
  40. word = TextAreaField(_('Signature:'), [Length(max=256)])
  41. class PasswordForm(Form):
  42. old_password = PasswordField(
  43. _('Old Password:'), [DataRequired(), Length(
  44. min=4, max=20)])
  45. new_password = PasswordField(
  46. _('New Password:'), [DataRequired(), Length(
  47. min=4, max=20)])
  48. rnew_password = PasswordField(
  49. _('New Password again:'), [DataRequired(), EqualTo('new_password')])
  50. class BabelForm(Form):
  51. timezone = SelectField(_('Timezone:'), coerce=str, choices=timezone)
  52. locale = SelectField(_('Locale:'), coerce=str, choices=locale)