Ticket #7499: time_input_widget.3.diff

File time_input_widget.3.diff, 1.3 KB (added by Kevin McConnell, 16 years ago)

Check TimeInput argument type (patched against r8507)

  • django/forms/widgets.py

     
    1616from django.utils.encoding import StrAndUnicode, force_unicode
    1717from django.utils.safestring import mark_safe
    1818from django.utils import datetime_safe
     19from datetime import time
    1920from util import flatatt
    2021from urlparse import urljoin
    2122
     
    307308    def render(self, name, value, attrs=None):
    308309        if value is None:
    309310            value = ''
    310         elif hasattr(value, 'replace'):
     311        elif isinstance(value, time):
    311312            value = value.replace(microsecond=0)
    312313        return super(TimeInput, self).render(name, value, attrs)
    313314
  • tests/regressiontests/forms/widgets.py

     
    11041104u'<input type="text" name="time" value="12:51:34" />'
    11051105>>> w.render('time', datetime.time(12, 51))
    11061106u'<input type="text" name="time" value="12:51:00" />'
     1107
     1108We should be able to initialize from a unicode value.
     1109>>> w.render('time', u'13:12:11')
     1110u'<input type="text" name="time" value="13:12:11" />'
    11071111"""
    11081112
Back to Top