Ticket #13621: ticket13621-alternative2.diff

File ticket13621-alternative2.diff, 2.3 KB (added by jacmkno, 14 years ago)

An alternative patch. Changes the validations to verify the localize field option before validating the format.

  • django/forms/fields.py

     
    337337            return value.date()
    338338        if isinstance(value, datetime.date):
    339339            return value
    340         for format in self.input_formats or formats.get_format('DATE_INPUT_FORMATS'):
     340        for format in self.input_formats or formats.get_format('DATE_INPUT_FORMATS', self.localize):
    341341            try:
    342342                return datetime.date(*time.strptime(value, format)[:3])
    343343            except ValueError:
     
    363363            return None
    364364        if isinstance(value, datetime.time):
    365365            return value
    366         for format in self.input_formats or formats.get_format('TIME_INPUT_FORMATS'):
     366        for format in self.input_formats or formats.get_format('TIME_INPUT_FORMATS', self.localize):
    367367            try:
    368368                return datetime.time(*time.strptime(value, format)[3:6])
    369369            except ValueError:
     
    397397            if len(value) != 2:
    398398                raise ValidationError(self.error_messages['invalid'])
    399399            value = '%s %s' % tuple(value)
    400         for format in self.input_formats or formats.get_format('DATETIME_INPUT_FORMATS'):
     400        for format in self.input_formats or formats.get_format('DATETIME_INPUT_FORMATS', self.localize):
    401401            try:
    402402                return datetime.datetime(*time.strptime(value, format)[:6])
    403403            except ValueError:
  • django/utils/formats.py

     
    3434        modules.reverse()
    3535    return modules
    3636
    37 def get_format(format_type):
     37def get_format(format_type, L10N=True):
    3838    """
    3939    For a specific format type, returns the format for the current
    4040    language (locale), defaults to the format in the settings.
    4141    format_type is the name of the format, e.g. 'DATE_FORMAT'
    4242    """
    4343    format_type = smart_str(format_type)
    44     if settings.USE_L10N:
     44    if settings.USE_L10N and L10N:
    4545        for module in get_format_modules():
    4646            try:
    4747                return getattr(module, format_type)
Back to Top