Ticket #17165: trunk.diff

File trunk.diff, 1.9 KB (added by René Fleschenberg, 13 years ago)

Patch against trunk

  • tests/regressiontests/forms/tests/extra.py

     
    1010from django.forms.util import ErrorList
    1111from django.utils import translation, unittest
    1212from django.utils.encoding import force_unicode, smart_unicode
     13from django.utils.formats import get_format
    1314
    1415from .error_messages import AssertFormErrorsMixin
    1516
     
    697698        w = SelectDateWidget(years=('1899',))
    698699        self.assertEqual(w.value_from_datadict({'date_year': '1899', 'date_month': '8', 'date_day': '13'}, {}, 'date'), '13-08-1899')
    699700
     701        # _has_changed works correctly with a localized date format
     702        input_format = get_format('DATE_INPUT_FORMATS')[0]
     703        today = datetime.date.today()
     704        today_l10n = today.strftime(input_format)
     705        tomorrow = today + datetime.timedelta(days=1)
     706        self.assertEqual(w._has_changed(today, today_l10n), False)
     707        self.assertEqual(w._has_changed(tomorrow, today_l10n), True)
     708
    700709    def test_l10n_invalid_date_in(self):
    701710        # Invalid dates shouldn't be allowed
    702711        a = GetDate({'mydate_month':'2', 'mydate_day':'31', 'mydate_year':'2010'})
  • django/forms/extras/widgets.py

     
    134134        s = Select(choices=choices)
    135135        select_html = s.render(field % name, val, local_attrs)
    136136        return select_html
     137
     138    def _has_changed(self, initial, data):
     139        input_format = get_format('DATE_INPUT_FORMATS')[0]
     140        data = datetime_safe.datetime.strptime(data, input_format).date()
     141        return super(SelectDateWidget, self)._has_changed(initial, data)
Back to Top