diff --git a/django/utils/formats.py b/django/utils/formats.py
index 77479ae..ad6127e 100644
a
|
b
|
def localize(value):
|
80 | 80 | formatted as a string using current locale format |
81 | 81 | """ |
82 | 82 | if settings.USE_L10N: |
83 | | if isinstance(value, decimal.Decimal): |
84 | | return number_format(value) |
85 | | elif isinstance(value, float): |
86 | | return number_format(value) |
87 | | elif isinstance(value, int): |
| 83 | if isinstance(value, (decimal.Decimal, float, int)): |
88 | 84 | return number_format(value) |
89 | 85 | elif isinstance(value, datetime.datetime): |
90 | 86 | return date_format(value, 'DATETIME_FORMAT') |
… |
… |
def localize_input(value, default=None):
|
99 | 95 | Checks if an input value is a localizable type and returns it |
100 | 96 | formatted with the appropriate formatting string of the current locale. |
101 | 97 | """ |
| 98 | |
| 99 | if isinstance(value, (decimal.Decimal, float, int)): |
| 100 | return number_format(value) |
102 | 101 | if isinstance(value, datetime.datetime): |
103 | 102 | value = datetime_safe.new_datetime(value) |
104 | 103 | 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 56f1585..2ff5fc4 100644
a
|
b
|
class TestModel(models.Model):
|
8 | 8 | class Company(models.Model): |
9 | 9 | name = models.CharField(max_length=50) |
10 | 10 | date_added = models.DateTimeField(default=datetime(1799,1,31,23,59,59,0)) |
| 11 | cents_payed = models.DecimalField(max_digits=4, decimal_places=2) |
11 | 12 | |
12 | 13 | __test__ = {'API_TESTS': ''' |
13 | 14 | >>> tm = TestModel() |
diff --git a/tests/regressiontests/i18n/tests.py b/tests/regressiontests/i18n/tests.py
index c2a39cd..e9ba9a7 100644
a
|
b
|
class FormattingTests(TestCase):
|
362 | 362 | form6 = CompanyForm({ |
363 | 363 | 'name': u'acme', |
364 | 364 | 'date_added': datetime.datetime(2009, 12, 31, 6, 0, 0), |
| 365 | 'cents_payed': decimal.Decimal("59.47"), |
365 | 366 | }) |
366 | 367 | form6.save() |
367 | 368 | self.assertEqual(True, form6.is_valid()) |
368 | 369 | self.assertEqual( |
369 | 370 | form6.as_ul(), |
370 | | u'<li><label for="id_name">Name:</label> <input id="id_name" type="text" name="name" value="acme" maxlength="50" /></li>\n<li><label for="id_date_added">Date added:</label> <input type="text" name="date_added" value="31.12.2009 06:00:00" id="id_date_added" /></li>' |
| 371 | u'<li><label for="id_name">Name:</label> <input id="id_name" type="text" name="name" value="acme" maxlength="50" /></li>\n<li><label for="id_date_added">Date added:</label> <input type="text" name="date_added" value="31.12.2009 06:00:00" id="id_date_added" /></li>\n<li><label for="id_cents_payed">Cents payed:</label> <input type="text" name="cents_payed" value="59,47" id="id_cents_payed" /></li>' |
371 | 372 | ) |
372 | 373 | self.assertEqual(localize_input(datetime.datetime(2009, 12, 31, 6, 0, 0)), '31.12.2009 06:00:00') |
373 | 374 | self.assertEqual(datetime.datetime(2009, 12, 31, 6, 0, 0), form6.cleaned_data['date_added']) |