Ticket #16404: diff_django_humanize_fix.diff

File diff_django_humanize_fix.diff, 2.3 KB (added by grepsd@…, 13 years ago)

fix the humanize.intcomma template filter to force the use of grouping in the number_format.format method.

  • django/contrib/humanize/templatetags/humanize.py

     
    4141        except (TypeError, ValueError):
    4242            return intcomma(value, False)
    4343        else:
    44             return number_format(value)
     44            return number_format(value, force_grouping=True)
    4545    orig = force_unicode(value)
    4646    new = re.sub("^(-?\d+)(\d{3})", '\g<1>,\g<2>', orig)
    4747    if orig == new:
  • django/utils/numberformat.py

     
    22from django.utils.safestring import mark_safe
    33
    44
    5 def format(number, decimal_sep, decimal_pos=None, grouping=0, thousand_sep=''):
     5def format(number, decimal_sep, decimal_pos=None, grouping=0, thousand_sep='', force_grouping=False):
    66    """
    77    Gets a number (as a number or string), and returns it as a string,
    88    using formats definied as arguments:
     
    1313    * thousand_sep: Thousand separator symbol (for example ",")
    1414
    1515    """
    16     use_grouping = settings.USE_L10N and \
     16    use_grouping = force_grouping or settings.USE_L10N and \
    1717        settings.USE_THOUSAND_SEPARATOR and grouping
    1818    # Make the common case fast:
    1919    if isinstance(number, int) and not use_grouping and not decimal_pos:
  • django/utils/formats.py

     
    103103    """
    104104    return dateformat.time_format(value, get_format(format or 'TIME_FORMAT', use_l10n=use_l10n))
    105105
    106 def number_format(value, decimal_pos=None, use_l10n=None):
     106def number_format(value, decimal_pos=None, use_l10n=None, force_grouping=False):
    107107    """
    108108    Formats a numeric value using localization settings
    109109
     
    120120        decimal_pos,
    121121        get_format('NUMBER_GROUPING', lang, use_l10n=use_l10n),
    122122        get_format('THOUSAND_SEPARATOR', lang, use_l10n=use_l10n),
     123        force_grouping=force_grouping
    123124    )
    124125
    125126def localize(value, use_l10n=None):
Back to Top