Ticket #12858: django_datefield_has_changed_fix.diff

File django_datefield_has_changed_fix.diff, 1.2 KB (added by camillo, 5 years ago)

patch fixing the bug

  • django/forms/widgets.py

     
    1111from django.utils.encoding import StrAndUnicode, force_unicode
    1212from django.utils.safestring import mark_safe
    1313from django.utils import datetime_safe, formats
    14 from datetime import time
     14import time
     15import datetime
     16from django.utils.formats import get_format
    1517from util import flatatt
    1618from urlparse import urljoin
    1719
     
    309311        return super(DateInput, self).render(name, value, attrs)
    310312
    311313    def _has_changed(self, initial, data):
     314        # if our field has show_hidden_initial == True, initial will be a string formatted by
     315        # HiddenInput using formats.localize_input, which is not necessarily the format used for
     316        # this DateInput widget. Attempt to convert it.
     317        try:
     318            initial = datetime.date(*time.strptime(initial, get_format('DATE_INPUT_FORMATS')[0])[:3])
     319        except (TypeError, ValueError):
     320            pass
    312321        return super(DateInput, self)._has_changed(self._format_value(initial), data)
    313322
    314323class DateTimeInput(Input):
Back to Top