Ticket #3852: django-selectdatewidget-datetime.patch

File django-selectdatewidget-datetime.patch, 966 bytes (added by Simon Law <simon@…>, 17 years ago)

Patch that only does coersion when value is a basestring.

  • django/newforms/extras/widgets.py

    # HG changeset patch
    # User Daniel Cuenca <daniel@akoha.org>
    # Date 1207172270 14400
    # Node ID 3645c413c464193ea0abde1687d882befd965ed2
    # Parent  18041c06e124891c79d5732657a07b591c009d74
    SelectDateWidget can now parse datetime objects.
    
    diff --git a/django/newforms/extras/widgets.py b/django/newforms/extras/widgets.py
    a b class SelectDateWidget(Widget):  
    3131            self.years = range(this_year, this_year+10)
    3232
    3333    def render(self, name, value, attrs=None):
    34         try:
     34        if isinstance(value, basestring):
    3535            value = datetime.date(*map(int, value.split('-')))
    36             year_val, month_val, day_val = value.year, value.month, value.day
    37         except (AttributeError, TypeError, ValueError):
    38             year_val = month_val = day_val = None
     36        year_val, month_val, day_val = value.year, value.month, value.day
    3937
    4038        output = []
    4139
Back to Top