Ticket #16404: diff_django_humanize_fix.diff
File diff_django_humanize_fix.diff, 2.3 KB (added by , 13 years ago) |
---|
-
django/contrib/humanize/templatetags/humanize.py
41 41 except (TypeError, ValueError): 42 42 return intcomma(value, False) 43 43 else: 44 return number_format(value )44 return number_format(value, force_grouping=True) 45 45 orig = force_unicode(value) 46 46 new = re.sub("^(-?\d+)(\d{3})", '\g<1>,\g<2>', orig) 47 47 if orig == new: -
django/utils/numberformat.py
2 2 from django.utils.safestring import mark_safe 3 3 4 4 5 def format(number, decimal_sep, decimal_pos=None, grouping=0, thousand_sep='' ):5 def format(number, decimal_sep, decimal_pos=None, grouping=0, thousand_sep='', force_grouping=False): 6 6 """ 7 7 Gets a number (as a number or string), and returns it as a string, 8 8 using formats definied as arguments: … … 13 13 * thousand_sep: Thousand separator symbol (for example ",") 14 14 15 15 """ 16 use_grouping = settings.USE_L10N and \16 use_grouping = force_grouping or settings.USE_L10N and \ 17 17 settings.USE_THOUSAND_SEPARATOR and grouping 18 18 # Make the common case fast: 19 19 if isinstance(number, int) and not use_grouping and not decimal_pos: -
django/utils/formats.py
103 103 """ 104 104 return dateformat.time_format(value, get_format(format or 'TIME_FORMAT', use_l10n=use_l10n)) 105 105 106 def number_format(value, decimal_pos=None, use_l10n=None ):106 def number_format(value, decimal_pos=None, use_l10n=None, force_grouping=False): 107 107 """ 108 108 Formats a numeric value using localization settings 109 109 … … 120 120 decimal_pos, 121 121 get_format('NUMBER_GROUPING', lang, use_l10n=use_l10n), 122 122 get_format('THOUSAND_SEPARATOR', lang, use_l10n=use_l10n), 123 force_grouping=force_grouping 123 124 ) 124 125 125 126 def localize(value, use_l10n=None):