Ticket #18777: django_date_time_hidden.patch

File django_date_time_hidden.patch, 1.0 KB (added by César H. Roldán, 12 years ago)
  • django/forms/widgets.py

     django/forms/widgets.py | 13 +++++++++++++
     1 file changed, 13 insertions(+)
    
    diff --git a/django/forms/widgets.py b/django/forms/widgets.py
    index fe7c06f..64317e5 100644
    a b class Input(Widget):  
    248248    """
    249249    input_type = None # Subclasses must define this.
    250250
     251    dt_formats = {
     252        datetime.date: 'DATE_INPUT_FORMATS',
     253        datetime.datetime: 'DATETIME_INPUT_FORMATS',
     254        datetime.time: 'TIME_INPUT_FORMATS',
     255    }
     256
    251257    def _format_value(self, value):
    252258        if self.is_localized:
    253259            return formats.localize_input(value)
     260        elif hasattr(value, 'strftime'):
     261            format = formats.get_format(self.dt_formats[type(value)])[0]
     262            if type(value) is datetime.date:
     263                value = datetime_safe.new_date(value)
     264            if type(value) is datetime.datetime:
     265                value = datetime_safe.new_datetime(value)
     266            return value.strftime(format)
    254267        return value
    255268
    256269    def render(self, name, value, attrs=None):
Back to Top