Django

Code

Changeset 3077

Show
Ignore:
Timestamp:
06/03/06 20:03:48 (2 years ago)
Author:
adrian
Message:

Fixed #1684 -- Added apnumber template filter in django.contrib.humanize. Thanks, ubernostrum

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/contrib/humanize/templatetags/humanize.py

    r3076 r3077  
    4949    return value 
    5050register.filter(intword) 
     51 
     52def apnumber(value): 
     53    """ 
     54    For numbers 1-9, returns the number spelled out. Otherwise, returns the 
     55    number. This follows Associated Press style. 
     56    """ 
     57    try: 
     58        value = int(value) 
     59    except ValueError: 
     60        return value 
     61    if not 0 < value < 10: 
     62        return value 
     63    return ('one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine')[value-1] 
     64register.filter(apnumber) 
  • django/trunk/docs/add_ons.txt

    r3076 r3077  
    5454in a template, and you'll have access to these filters: 
    5555 
    56 ordinal 
    57 ------- 
     56apnumber 
     57-------- 
    5858 
    59 Converts an integer to its ordinal as a string. 
     59For numbers 1-9, returns the number spelled out. Otherwise, returns the 
     60number. This follows Associated Press style. 
    6061 
    6162Examples: 
    6263 
    63     * ``1`` becomes ``'1st'``. 
    64     * ``2`` becomes ``'2nd'``. 
    65     * ``3`` becomes ``'3rd'``. 
     64    * ``1`` becomes ``'one'``. 
     65    * ``2`` becomes ``'two'``. 
     66    * ``10`` becomes ``10``. 
    6667 
    6768You can pass in either an integer or a string representation of an integer. 
     
    9495 
    9596Values up to 1000000000000000 (one quadrillion) are supported. 
     97 
     98You can pass in either an integer or a string representation of an integer. 
     99 
     100ordinal 
     101------- 
     102 
     103Converts an integer to its ordinal as a string. 
     104 
     105Examples: 
     106 
     107    * ``1`` becomes ``'1st'``. 
     108    * ``2`` becomes ``'2nd'``. 
     109    * ``3`` becomes ``'3rd'``. 
    96110 
    97111You can pass in either an integer or a string representation of an integer.