#18519: DateField ignores DATE_INPUT_FORMATS (because get_format ignores it)
-----------------------------+---------------------------------------------
     Reporter:               |      Owner:  nobody
  marcin.tustin@…            |     Status:  new
         Type:  Bug          |    Version:  1.4
    Component:  Forms        |   Keywords:  DateField, django.utils.formats
     Severity:  Normal       |  Has patch:  0
 Triage Stage:  Unreviewed   |      UI/UX:  0
Easy pickings:  1            |
-----------------------------+---------------------------------------------
 DateFields in forms do not have their behaviour altered by the setting
 DATE_INPUT_FORMATS.

 This happens because django.utils.get_format ignores it.

 Here is a transcript of a debug session demonstrating that:


 {{{
 In [14]: df.to_python('13-03-1978')
 ---------------------------------------------------------------------------
 ValidationError                           Traceback (most recent call
 last)
 /home/marcintustin/webapps/django/oneclickcosvirt/lib/python2.7/site-
 packages/django/core/management/commands/shell.pyc in <module>()
 ----> 1 df.to_python('13-03-1978')

 /home/marcintustin/webapps/django/oneclickcosvirt/lib/python2.7/site-
 packages/django/forms/fields.pyc in to_python(self, value)
     377         if isinstance(value, datetime.date):
     378             return value
 --> 379         return super(DateField, self).to_python(value)
     380
     381     def strptime(self, value, format):

 /home/marcintustin/webapps/django/oneclickcosvirt/lib/python2.7/site-
 packages/django/forms/fields.pyc in to_python(self, value)
     354                         except ValueError:
     355                             continue
 --> 356         raise ValidationError(self.error_messages['invalid'])
     357
     358     def strptime(self, value, format):

 ValidationError: [u'Enter a valid date.']

 In [15]: import pdb; pdb.pm()
 > /home/marcintustin/webapps/django/oneclickcosvirt/lib/python2.7/site-
 packages/django/forms/fields.py(356)to_python()
 -> raise ValidationError(self.error_messages['invalid'])
 (Pdb) l
 351                                 usecs = int(usecs_str[:6].ljust(6,
 '0'))
 352                                 dt =
 datetime.datetime.strptime(datetime_str, format[:-3])
 353                                 return dt.replace(microsecond=usecs)
 354                             except ValueError:
 355                                 continue
 356  ->         raise ValidationError(self.error_messages['invalid'])
 357
 358         def strptime(self, value, format):
 359             raise NotImplementedError('Subclasses must define this
 method.')
 360
 361     class DateField(BaseTemporalField):
 (Pdb) format
 '%m/%d/%y'
 (Pdb) self.input_formats
 <django.utils.functional.__proxy__ object at 0x20da390>
 (Pdb) list(self.input_formats)
 *** Error in argument: '(self.input_formats)'
 (Pdb) self.input_formats
 <django.utils.functional.__proxy__ object at 0x20da390>
 (Pdb) tuple(self.input_formats)
 ('%Y-%m-%d', '%m/%d/%Y', '%m/%d/%y')
 (Pdb) self
 <django.forms.fields.DateField object at 0x347fdd0>
 (Pdb) formats
 <module 'django.utils.formats' from
 '/home/marcintustin/webapps/django/oneclickcosvirt/lib/python2.7/site-
 packages/django/utils/formats.pyc'>
 (Pdb) formats.get_format_lazy('DATE_INPUT_FORMATS')
 <django.utils.functional.__proxy__ object at 0x3537650>
 (Pdb) tuple(formats.get_format_lazy('DATE_INPUT_FORMATS'))
 ('%Y-%m-%d', '%m/%d/%Y', '%m/%d/%y')
 (Pdb) from django.conf import settings
 (Pdb) settings.DATE_INPUT_FORMATS
 ('%d-%m-%y', '%d-%b-%Y', '%d-%B-%y', '%d-%m-%Y', '%d-%b-%y', '%d-%B-%Y',
 '%d/%m/%y', '%d/%b/%Y', '%d/%B/%y', '%d/%m/%Y', '%d/%b/%y', '%d/%B/%Y',
 '%d %m %y', '%d %b %Y', '%d %B %y', '%d %m %Y', '%d %b %y', '%d %B %Y',
 '%Y-%m-%d', '%m/%d/%Y', '%m/%d/%y', '%b %d %Y', '%b %d, %Y', '%d %b %Y',
 '%d %b, %Y', '%B %d %Y', '%B %d, %Y', '%d %B %Y', '%d %B, %Y', '%x')
 (Pdb) getattr(settings, 'DATE_INPUT_FORMATS')
 ('%d-%m-%y', '%d-%b-%Y', '%d-%B-%y', '%d-%m-%Y', '%d-%b-%y', '%d-%B-%Y',
 '%d/%m/%y', '%d/%b/%Y', '%d/%B/%y', '%d/%m/%Y', '%d/%b/%y', '%d/%B/%Y',
 '%d %m %y', '%d %b %Y', '%d %B %y', '%d %m %Y', '%d %b %y', '%d %B %Y',
 '%Y-%m-%d', '%m/%d/%Y', '%m/%d/%y', '%b %d %Y', '%b %d, %Y', '%d %b %Y',
 '%d %b, %Y', '%B %d %Y', '%B %d, %Y', '%d %B %Y', '%d %B, %Y', '%x')
 (Pdb) formats.get_format('DATE_INPUT_FORMATS')
 ('%Y-%m-%d', '%m/%d/%Y', '%m/%d/%y')
 (Pdb)
 }}}

-- 
Ticket URL: <https://code.djangoproject.com/ticket/18519>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-updates@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to