html5.py 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. """
  2. Widgets for various HTML5 input types.
  3. """
  4. from .core import Input
  5. __all__ = (
  6. 'ColorInput', 'DateInput', 'DateTimeInput', 'DateTimeLocalInput',
  7. 'EmailInput', 'MonthInput', 'NumberInput', 'RangeInput', 'SearchInput',
  8. 'TelInput', 'TimeInput', 'URLInput', 'WeekInput',
  9. )
  10. class SearchInput(Input):
  11. """
  12. Renders an input with type "search".
  13. """
  14. input_type = 'search'
  15. class TelInput(Input):
  16. """
  17. Renders an input with type "tel".
  18. """
  19. input_type = 'tel'
  20. class URLInput(Input):
  21. """
  22. Renders an input with type "url".
  23. """
  24. input_type = 'url'
  25. class EmailInput(Input):
  26. """
  27. Renders an input with type "email".
  28. """
  29. input_type = 'email'
  30. class DateTimeInput(Input):
  31. """
  32. Renders an input with type "datetime".
  33. """
  34. input_type = 'datetime'
  35. class DateInput(Input):
  36. """
  37. Renders an input with type "date".
  38. """
  39. input_type = 'date'
  40. class MonthInput(Input):
  41. """
  42. Renders an input with type "month".
  43. """
  44. input_type = 'month'
  45. class WeekInput(Input):
  46. """
  47. Renders an input with type "week".
  48. """
  49. input_type = 'week'
  50. class TimeInput(Input):
  51. """
  52. Renders an input with type "time".
  53. """
  54. input_type = 'time'
  55. class DateTimeLocalInput(Input):
  56. """
  57. Renders an input with type "datetime-local".
  58. """
  59. input_type = 'datetime-local'
  60. class NumberInput(Input):
  61. """
  62. Renders an input with type "number".
  63. """
  64. input_type = 'number'
  65. def __init__(self, step=None, min=None, max=None):
  66. self.step = step
  67. self.min = min
  68. self.max = max
  69. def __call__(self, field, **kwargs):
  70. if self.step is not None:
  71. kwargs.setdefault('step', self.step)
  72. if self.min is not None:
  73. kwargs.setdefault('min', self.min)
  74. if self.max is not None:
  75. kwargs.setdefault('max', self.max)
  76. return super(NumberInput, self).__call__(field, **kwargs)
  77. class RangeInput(Input):
  78. """
  79. Renders an input with type "range".
  80. """
  81. input_type = 'range'
  82. def __init__(self, step=None):
  83. self.step = step
  84. def __call__(self, field, **kwargs):
  85. if self.step is not None:
  86. kwargs.setdefault('step', self.step)
  87. return super(RangeInput, self).__call__(field, **kwargs)
  88. class ColorInput(Input):
  89. """
  90. Renders an input with type "color".
  91. """
  92. input_type = 'color'