| 57 | import locale |
| 58 | test_locale_available = False |
| 59 | try: |
| 60 | locale.setlocale(locale.LC_NUMERIC,'fr_FR') |
| 61 | test_locale_available = True |
| 62 | except: |
| 63 | pass |
| 64 | |
| 65 | if test_locale_available: |
| 66 | __test__['LOCALE_TESTS'] = """ |
| 67 | # check for #6783 |
| 68 | >>> from django.db.models.fields import DecimalField |
| 69 | >>> import locale |
| 70 | >>> pre_locale = locale.getlocale()[0] |
| 71 | >>> d = DecimalField(max_digits=6, decimal_places=3) |
| 72 | >>> locale.setlocale(locale.LC_NUMERIC,'fr_FR') |
| 73 | 'fr_FR' |
| 74 | >>> print "%.1f" % 2.3 |
| 75 | 2.3 |
| 76 | |
| 77 | # locale is in effect, but print doesn't use it, and neither does DecimalField.format_number |
| 78 | >>> locale.format("%.1f",2.3) |
| 79 | '2,3' |
| 80 | >>> print d.format_number(3.456) |
| 81 | 3.456 |
| 82 | |
| 83 | # we can safely save decimalfields into the DB even with the funky locale |
| 84 | >>> m = Movie(name = "Rambo", rating = 4.2) |
| 85 | >>> m.save() |
| 86 | >>> res = locale.setlocale(locale.LC_NUMERIC, pre_locale) |