forms.py 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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-05-21 22:46:35 (CST)
  9. # Last Update:星期一 2016-7-25 17:43:3 (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 pytz import all_timezones
  18. choices = [(1, _('Everybody')), (2, _('Logined User')), (3, _('Only Self'))]
  19. class PrivacyForm(Form):
  20. online_status = SelectField(
  21. _('Login status:'), coerce=int,
  22. choices=choices)
  23. topic_list = SelectField(_('Topic List:'), coerce=int, choices=choices)
  24. rep_list = SelectField(_('Reply List:'), coerce=int, choices=choices)
  25. ntb_list = SelectField(_('Notebook List:'), coerce=int, choices=choices)
  26. collect_list = SelectField(_('Collect List:'), coerce=int, choices=choices)
  27. class ProfileForm(Form):
  28. introduce = TextAreaField(_('Introduce:'), [Length(max=256)])
  29. school = StringField(_('School:'), [Length(max=256)])
  30. word = TextAreaField(_('Signature:'), [Length(max=256)])
  31. class PasswordForm(Form):
  32. password = PasswordField(
  33. _('Old Password:'), [DataRequired(), Length(min=4, max=20)])
  34. password_n = PasswordField(
  35. _('New Password:'),
  36. [DataRequired(), Length(min=4, max=20), EqualTo('password_nn')])
  37. password_nn = PasswordField(_('New Password again:'), [DataRequired()])
  38. class BabelForm(Form):
  39. timezone = SelectField(
  40. _('Timezone:'), choices=[(i, i) for i in all_timezones])
  41. locale = SelectField(
  42. _('Locale:'),
  43. choices=[('en', _('English')), ('zh', _('Chinese'))])