simple.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import warnings
  2. from .. import widgets
  3. from .core import StringField, BooleanField
  4. __all__ = (
  5. 'BooleanField', 'TextAreaField', 'PasswordField', 'FileField',
  6. 'HiddenField', 'SubmitField', 'TextField'
  7. )
  8. class TextField(StringField):
  9. """
  10. Legacy alias for StringField
  11. .. deprecated:: 2.0
  12. """
  13. def __init__(self, *args, **kw):
  14. super(TextField, self).__init__(*args, **kw)
  15. warnings.warn(
  16. 'The TextField alias for StringField has been deprecated and will be removed in WTForms 3.0',
  17. DeprecationWarning, stacklevel=2
  18. )
  19. class TextAreaField(StringField):
  20. """
  21. This field represents an HTML ``<textarea>`` and can be used to take
  22. multi-line input.
  23. """
  24. widget = widgets.TextArea()
  25. class PasswordField(StringField):
  26. """
  27. A StringField, except renders an ``<input type="password">``.
  28. Also, whatever value is accepted by this field is not rendered back
  29. to the browser like normal fields.
  30. """
  31. widget = widgets.PasswordInput()
  32. class FileField(StringField):
  33. """
  34. Can render a file-upload field. Will take any passed filename value, if
  35. any is sent by the browser in the post params. This field will NOT
  36. actually handle the file upload portion, as wtforms does not deal with
  37. individual frameworks' file handling capabilities.
  38. """
  39. widget = widgets.FileInput()
  40. class HiddenField(StringField):
  41. """
  42. HiddenField is a convenience for a StringField with a HiddenInput widget.
  43. It will render as an ``<input type="hidden">`` but otherwise coerce to a string.
  44. """
  45. widget = widgets.HiddenInput()
  46. class SubmitField(BooleanField):
  47. """
  48. Represents an ``<input type="submit">``. This allows checking if a given
  49. submit button has been pressed.
  50. """
  51. widget = widgets.SubmitInput()