Ticket #16878: 16878.diff

File 16878.diff, 3.3 KB (added by Julien Phalip, 13 years ago)
  • django/contrib/humanize/templatetags/humanize.py

    diff --git a/django/contrib/humanize/templatetags/humanize.py b/django/contrib/humanize/templatetags/humanize.py
    index d071c3a..ece9cb7 100644
    a b from datetime import date, datetime, timedelta  
    44from django import template
    55from django.conf import settings
    66from django.template import defaultfilters
     7from django.utils.datastructures import SortedDict
    78from django.utils.encoding import force_unicode
    89from django.utils.formats import number_format
    910from django.utils.translation import pgettext, ungettext, ugettext as _
    def intcomma(value, use_l10n=True):  
    5152intcomma.is_safe = True
    5253register.filter(intcomma)
    5354
    54 # A dictionary of standard large number to their converters
    55 intword_converters = {
    56     6: lambda number: (
     55# A sorted dictionary of standard large number to their converters
     56intword_converters = SortedDict((
     57    (6, lambda number: (
    5758        ungettext('%(value).1f million', '%(value).1f million', number),
    5859        ungettext('%(value)s million', '%(value)s million', number),
    59     ),
    60     9: lambda number: (
     60    )),
     61    (9, lambda number: (
    6162        ungettext('%(value).1f billion', '%(value).1f billion', number),
    6263        ungettext('%(value)s billion', '%(value)s billion', number),
    63     ),
    64     12: lambda number: (
     64    )),
     65    (12, lambda number: (
    6566        ungettext('%(value).1f trillion', '%(value).1f trillion', number),
    6667        ungettext('%(value)s trillion', '%(value)s trillion', number),
    67     ),
    68     15: lambda number: (
     68    )),
     69    (15, lambda number: (
    6970        ungettext('%(value).1f quadrillion', '%(value).1f quadrillion', number),
    7071        ungettext('%(value)s quadrillion', '%(value)s quadrillion', number),
    71     ),
    72     18: lambda number: (
     72    )),
     73    (18, lambda number: (
    7374        ungettext('%(value).1f quintillion', '%(value).1f quintillion', number),
    7475        ungettext('%(value)s quintillion', '%(value)s quintillion', number),
    75     ),
    76     21: lambda number: (
     76    )),
     77    (21, lambda number: (
    7778        ungettext('%(value).1f sextillion', '%(value).1f sextillion', number),
    7879        ungettext('%(value)s sextillion', '%(value)s sextillion', number),
    79     ),
    80     24: lambda number: (
     80    )),
     81    (24, lambda number: (
    8182        ungettext('%(value).1f septillion', '%(value).1f septillion', number),
    8283        ungettext('%(value)s septillion', '%(value)s septillion', number),
    83     ),
    84     27: lambda number: (
     84    )),
     85    (27, lambda number: (
    8586        ungettext('%(value).1f octillion', '%(value).1f octillion', number),
    8687        ungettext('%(value)s octillion', '%(value)s octillion', number),
    87     ),
    88     30: lambda number: (
     88    )),
     89    (30, lambda number: (
    8990        ungettext('%(value).1f nonillion', '%(value).1f nonillion', number),
    9091        ungettext('%(value)s nonillion', '%(value)s nonillion', number),
    91     ),
    92     33: lambda number: (
     92    )),
     93    (33, lambda number: (
    9394        ungettext('%(value).1f decillion', '%(value).1f decillion', number),
    9495        ungettext('%(value)s decillion', '%(value)s decillion', number),
    95     ),
    96     100: lambda number: (
     96    )),
     97    (100, lambda number: (
    9798        ungettext('%(value).1f googol', '%(value).1f googol', number),
    9899        ungettext('%(value)s googol', '%(value)s googol', number),
    99     ),
    100 }
     100    )),
     101))
    101102
    102103def intword(value):
    103104    """
Back to Top