Ticket #5917: SelectDate_datetime.3.patch

File SelectDate_datetime.3.patch, 825 bytes (added by Martin Conte Mac Donell <Reflejo@…>, 17 years ago)

This is IMHO a better way to do that (Err.. Sorry for the other ones)

  • django/newforms/extras/widgets.py

     
    33"""
    44
    55import datetime
     6from types import StringTypes
    67
    78from django.newforms.widgets import Widget, Select
    89from django.utils.dates import MONTHS
     
    3233
    3334    def render(self, name, value, attrs=None):
    3435        try:
    35             value = datetime.date(*map(int, value.split('-')))
     36            if type(value) in StringTypes:
     37                value = datetime.date(*map(int, value.split('-')))
    3638            year_val, month_val, day_val = value.year, value.month, value.day
    3739        except (AttributeError, TypeError, ValueError):
    3840            year_val = month_val = day_val = None
Back to Top