Ticket #13054: 13054.diff

File 13054.diff, 6.4 KB (added by Ramiro Morales, 15 years ago)
  • django/utils/numberformat.py

    diff --git a/django/utils/numberformat.py b/django/utils/numberformat.py
    a b  
    3030        dec_part = dec_part + ('0' * (decimal_pos - len(dec_part)))
    3131    if dec_part: dec_part = decimal_sep + dec_part
    3232    # grouping
    33     if settings.USE_THOUSAND_SEPARATOR and grouping:
     33    if settings.USE_L10N and settings.USE_THOUSAND_SEPARATOR and grouping:
    3434        int_part_gd = ''
    3535        for cnt, digit in enumerate(int_part[::-1]):
    3636            if cnt and not cnt % grouping:
  • tests/regressiontests/i18n/tests.py

    diff --git a/tests/regressiontests/i18n/tests.py b/tests/regressiontests/i18n/tests.py
    a b  
    66
    77from django.template import Template, Context
    88from django.conf import settings
    9 from django.utils.formats import get_format, date_format, time_format, number_format, localize, localize_input
    10 from django.utils.numberformat import format
    11 from django.test import TestCase, client
     9from django.utils.formats import get_format, date_format, time_format, localize, localize_input
     10from django.utils.numberformat import format as nformat
     11from django.test import TestCase
    1212from django.utils.translation import ugettext, ugettext_lazy, activate, deactivate, gettext_lazy, to_locale
    1313
    1414from forms import I18nForm, SelectDateForm, SelectDateWidget, CompanyForm
     
    106106        self.use_i18n = settings.USE_I18N
    107107        self.use_l10n = settings.USE_L10N
    108108        self.use_thousand_separator = settings.USE_THOUSAND_SEPARATOR
     109        self.thousand_separator = settings.THOUSAND_SEPARATOR
     110        self.number_grouping = settings.NUMBER_GROUPING
    109111        self.n = decimal.Decimal('66666.666')
    110112        self.f = 99999.999
    111113        self.d = datetime.date(2009, 12, 31)
     
    124126        settings.USE_I18N = self.use_i18n
    125127        settings.USE_L10N = self.use_l10n
    126128        settings.USE_THOUSAND_SEPARATOR = self.use_thousand_separator
     129        settings.THOUSAND_SEPARATOR = self.thousand_separator
     130        settings.NUMBER_GROUPING = self.number_grouping
    127131
    128132    def test_locale_independent(self):
    129133        """
     
    131135        """
    132136        settings.USE_L10N = True
    133137        settings.USE_THOUSAND_SEPARATOR = False
    134         self.assertEqual(u'66666.66', format(self.n, decimal_sep='.', decimal_pos=2, grouping=3, thousand_sep=','))
    135         self.assertEqual(u'66666A6', format(self.n, decimal_sep='A', decimal_pos=1, grouping=1, thousand_sep='B'))
     138        self.assertEqual(u'66666.66', nformat(self.n, decimal_sep='.', decimal_pos=2, grouping=3, thousand_sep=','))
     139        self.assertEqual(u'66666A6', nformat(self.n, decimal_sep='A', decimal_pos=1, grouping=1, thousand_sep='B'))
    136140
    137141        settings.USE_THOUSAND_SEPARATOR = True
    138         self.assertEqual(u'66,666.66', format(self.n, decimal_sep='.', decimal_pos=2, grouping=3, thousand_sep=','))
    139         self.assertEqual(u'6B6B6B6B6A6', format(self.n, decimal_sep='A', decimal_pos=1, grouping=1, thousand_sep='B'))
    140         self.assertEqual(u'-66666.6', format(-66666.666, decimal_sep='.', decimal_pos=1))
    141         self.assertEqual(u'-66666.0', format(int('-66666'), decimal_sep='.', decimal_pos=1))
     142        self.assertEqual(u'66,666.66', nformat(self.n, decimal_sep='.', decimal_pos=2, grouping=3, thousand_sep=','))
     143        self.assertEqual(u'6B6B6B6B6A6', nformat(self.n, decimal_sep='A', decimal_pos=1, grouping=1, thousand_sep='B'))
     144        self.assertEqual(u'-66666.6', nformat(-66666.666, decimal_sep='.', decimal_pos=1))
     145        self.assertEqual(u'-66666.0', nformat(int('-66666'), decimal_sep='.', decimal_pos=1))
    142146
    143147        # date filter
    144148        self.assertEqual(u'31.12.2009 в 20:50', Template('{{ dt|date:"d.m.Y в H:i" }}').render(self.ctxt))
     
    200204                u'<select name="mydate_month" id="id_mydate_month">\n<option value="1">gener</option>\n<option value="2">febrer</option>\n<option value="3">mar\xe7</option>\n<option value="4">abril</option>\n<option value="5">maig</option>\n<option value="6">juny</option>\n<option value="7">juliol</option>\n<option value="8">agost</option>\n<option value="9">setembre</option>\n<option value="10">octubre</option>\n<option value="11">novembre</option>\n<option value="12" selected="selected">desembre</option>\n</select>\n<select name="mydate_day" id="id_mydate_day">\n<option value="1">1</option>\n<option value="2">2</option>\n<option value="3">3</option>\n<option value="4">4</option>\n<option value="5">5</option>\n<option value="6">6</option>\n<option value="7">7</option>\n<option value="8">8</option>\n<option value="9">9</option>\n<option value="10">10</option>\n<option value="11">11</option>\n<option value="12">12</option>\n<option value="13">13</option>\n<option value="14">14</option>\n<option value="15">15</option>\n<option value="16">16</option>\n<option value="17">17</option>\n<option value="18">18</option>\n<option value="19">19</option>\n<option value="20">20</option>\n<option value="21">21</option>\n<option value="22">22</option>\n<option value="23">23</option>\n<option value="24">24</option>\n<option value="25">25</option>\n<option value="26">26</option>\n<option value="27">27</option>\n<option value="28">28</option>\n<option value="29">29</option>\n<option value="30">30</option>\n<option value="31" selected="selected">31</option>\n</select>\n<select name="mydate_year" id="id_mydate_year">\n<option value="2009" selected="selected">2009</option>\n<option value="2010">2010</option>\n<option value="2011">2011</option>\n<option value="2012">2012</option>\n<option value="2013">2013</option>\n<option value="2014">2014</option>\n<option value="2015">2015</option>\n<option value="2016">2016</option>\n<option value="2017">2017</option>\n<option value="2018">2018</option>\n</select>',
    201205                SelectDateWidget(years=range(2009, 2019)).render('mydate', datetime.date(2009, 12, 31))
    202206            )
     207
     208            # We shouldn't change the behavior of the floatformat filter re:
     209            # thousand separator and grouping when USE_L10N is False even
     210            # if the USE_THOUSAND_SEPARATOR, NUMBER_GROUPING and
     211            # THOUSAND_SEPARATOR settings are specified
     212            settings.USE_THOUSAND_SEPARATOR = True
     213            settings.NUMBER_GROUPING = 1
     214            settings.THOUSAND_SEPARATOR = '!'
     215            self.assertEqual(u'66666.67', Template('{{ n|floatformat:2 }}').render(self.ctxt))
     216            self.assertEqual(u'100000.0', Template('{{ f|floatformat }}').render(self.ctxt))
    203217        finally:
    204218            deactivate()
    205219
Back to Top