Author: adrian Date: 2006-06-03 20:03:48 -0500 (Sat, 03 Jun 2006) New Revision: 3077
Modified: django/trunk/django/contrib/humanize/templatetags/humanize.py django/trunk/docs/add_ons.txt Log: Fixed #1684 -- Added apnumber template filter in django.contrib.humanize. Thanks, ubernostrum Modified: django/trunk/django/contrib/humanize/templatetags/humanize.py =================================================================== --- django/trunk/django/contrib/humanize/templatetags/humanize.py 2006-06-04 00:58:39 UTC (rev 3076) +++ django/trunk/django/contrib/humanize/templatetags/humanize.py 2006-06-04 01:03:48 UTC (rev 3077) @@ -48,3 +48,17 @@ return '%.1f trillion' % (value / 1000000000000.0) return value register.filter(intword) + +def apnumber(value): + """ + For numbers 1-9, returns the number spelled out. Otherwise, returns the + number. This follows Associated Press style. + """ + try: + value = int(value) + except ValueError: + return value + if not 0 < value < 10: + return value + return ('one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine')[value-1] +register.filter(apnumber) Modified: django/trunk/docs/add_ons.txt =================================================================== --- django/trunk/docs/add_ons.txt 2006-06-04 00:58:39 UTC (rev 3076) +++ django/trunk/docs/add_ons.txt 2006-06-04 01:03:48 UTC (rev 3077) @@ -53,16 +53,17 @@ ``INSTALLED_APPS`` setting. Once you've done that, use ``{% load english %}`` in a template, and you'll have access to these filters: -ordinal -------- +apnumber +-------- -Converts an integer to its ordinal as a string. +For numbers 1-9, returns the number spelled out. Otherwise, returns the +number. This follows Associated Press style. Examples: - * ``1`` becomes ``'1st'``. - * ``2`` becomes ``'2nd'``. - * ``3`` becomes ``'3rd'``. + * ``1`` becomes ``'one'``. + * ``2`` becomes ``'two'``. + * ``10`` becomes ``10``. You can pass in either an integer or a string representation of an integer. @@ -96,6 +97,19 @@ You can pass in either an integer or a string representation of an integer. +ordinal +------- + +Converts an integer to its ordinal as a string. + +Examples: + + * ``1`` becomes ``'1st'``. + * ``2`` becomes ``'2nd'``. + * ``3`` becomes ``'3rd'``. + +You can pass in either an integer or a string representation of an integer. + flatpages ========= --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django updates" group. To post to this group, send email to django-updates@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-updates -~----------~----~----~----~------~----~------~--~---