Ticket #17165: 1.3.X.diff

File 1.3.X.diff, 1.8 KB (added by René Fleschenberg, 12 years ago)

Patch against the 1.3.X branch.

  • django/forms/extras/widgets.py

     
    139139        s = Select(choices=choices)
    140140        select_html = s.render(field % name, val, local_attrs)
    141141        return select_html
     142
     143    def _has_changed(self, initial, data):
     144        input_format = get_format('DATE_INPUT_FORMATS')[0]
     145        data = datetime_safe.datetime(*(time.strptime(data, input_format)[0:6])).date()
     146        return super(SelectDateWidget, self)._has_changed(initial, data)
  • tests/regressiontests/forms/tests/extra.py

     
    99from django.utils import unittest
    1010from django.utils.encoding import force_unicode
    1111from django.utils.encoding import smart_unicode
     12from django.utils.formats import get_format
    1213from error_messages import AssertFormErrorsMixin
    1314
    1415class GetDate(Form):
     
    610611<option value="2016">2016</option>
    611612</select>""")
    612613
     614        # _has_changed works correctly with a localized date format
     615        input_format = get_format('DATE_INPUT_FORMATS')[0]
     616        today = datetime.date.today()
     617        today_l10n = today.strftime(input_format)
     618        tomorrow = today + datetime.timedelta(days=1)
     619        self.assertEqual(w._has_changed(today, today_l10n), False)
     620        self.assertEqual(w._has_changed(tomorrow, today_l10n), True)
     621
    613622        # Years before 1900 work
    614623        w = SelectDateWidget(years=('1899',))
    615624        self.assertEqual(w.value_from_datadict({'date_year': '1899', 'date_month': '8', 'date_day': '13'}, {}, 'date'), '13-08-1899')
Back to Top