diff --git a/django/utils/formats.py b/django/utils/formats.py index 77479ae2a6..88f744b96d 100644 --- a/django/utils/formats.py +++ b/django/utils/formats.py @@ -80,11 +80,7 @@ def localize(value): formatted as a string using current locale format """ if settings.USE_L10N: - if isinstance(value, decimal.Decimal): - return number_format(value) - elif isinstance(value, float): - return number_format(value) - elif isinstance(value, int): + if isinstance(value, (decimal.Decimal, float, int)): return number_format(value) elif isinstance(value, datetime.datetime): return date_format(value, 'DATETIME_FORMAT') @@ -99,6 +95,8 @@ def localize_input(value, default=None): Checks if an input value is a localizable type and returns it formatted with the appropriate formatting string of the current locale. """ + if isinstance(value, (decimal.Decimal, float, int)): + return number_format(value) if isinstance(value, datetime.datetime): value = datetime_safe.new_datetime(value) format = smart_str(default or get_format('DATETIME_INPUT_FORMATS')[0]) diff --git a/tests/regressiontests/i18n/models.py b/tests/regressiontests/i18n/models.py index 56f158578b..2ff5fc4bd1 100644 --- a/tests/regressiontests/i18n/models.py +++ b/tests/regressiontests/i18n/models.py @@ -8,6 +8,7 @@ class TestModel(models.Model): class Company(models.Model): name = models.CharField(max_length=50) date_added = models.DateTimeField(default=datetime(1799,1,31,23,59,59,0)) + cents_payed = models.DecimalField(max_digits=4, decimal_places=2) __test__ = {'API_TESTS': ''' >>> tm = TestModel() diff --git a/tests/regressiontests/i18n/tests.py b/tests/regressiontests/i18n/tests.py index c2a39cd18a..212f952add 100644 --- a/tests/regressiontests/i18n/tests.py +++ b/tests/regressiontests/i18n/tests.py @@ -362,12 +362,13 @@ class FormattingTests(TestCase): form6 = CompanyForm({ 'name': u'acme', 'date_added': datetime.datetime(2009, 12, 31, 6, 0, 0), + 'cents_payed': decimal.Decimal('59.47'), }) form6.save() self.assertEqual(True, form6.is_valid()) self.assertEqual( form6.as_ul(), - u'