| 101 | class DateTextInput(TextInput): |
| 102 | """Renders value in text input using default or specified date format.""" |
| 103 | def __init__(self, format=None, attrs=None): |
| 104 | super(DateTextInput, self).__init__(attrs) |
| 105 | self.format = format or settings.DATE_FORMAT |
| 106 | |
| 107 | def render(self, name, value, attrs=None): |
| 108 | if value and (isinstance(value, datetime.date) or isinstance(value, datetime.datetime)): |
| 109 | formatted_value = dateformat.format(value, self.format) |
| 110 | else: |
| 111 | formatted_value = None |
| 112 | return super(DateTextInput, self).render(name, formatted_value, attrs) |
| 113 | |
| 114 | class TimeTextInput(TextInput): |
| 115 | """Renders time in text input using default or specified time format.""" |
| 116 | def __init__(self, format=None, attrs=None): |
| 117 | super(TimeTextInput, self).__init__(attrs) |
| 118 | self.format = format or settings.TIMEFORMAT |
| 119 | |
| 120 | def render(self, name, value, attrs=None): |
| 121 | if value and (isinstance(value, datetime.time) or isinstance(value, datetime.datetime)): |
| 122 | formatted_value = dateformat.time_format(value, self.format) |
| 123 | else: |
| 124 | formatted_value = None |
| 125 | return super(TimeTextInput, self).render(name, formatted_value, attrs) |
| 126 | |