Ticket #12858: django_datefield_has_changed_fix.diff
File django_datefield_has_changed_fix.diff, 1.2 KB (added by , 15 years ago) |
---|
-
django/forms/widgets.py
11 11 from django.utils.encoding import StrAndUnicode, force_unicode 12 12 from django.utils.safestring import mark_safe 13 13 from django.utils import datetime_safe, formats 14 from datetime import time 14 import time 15 import datetime 16 from django.utils.formats import get_format 15 17 from util import flatatt 16 18 from urlparse import urljoin 17 19 … … 309 311 return super(DateInput, self).render(name, value, attrs) 310 312 311 313 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 312 321 return super(DateInput, self)._has_changed(self._format_value(initial), data) 313 322 314 323 class DateTimeInput(Input):