summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorAdrian Holovaty <adrian@holovaty.com>2006-06-04 01:03:48 +0000
committerAdrian Holovaty <adrian@holovaty.com>2006-06-04 01:03:48 +0000
commitb8fd9a44e5a00ec1a3e857cd20442ec2572335d0 (patch)
treec06a884004565aa67e270221cd006ae020394cbb /django
parentfb537e177d7d304d6642ee6005258a82584a8032 (diff)
Fixed #1684 -- Added apnumber template filter in django.contrib.humanize. Thanks, ubernostrum
git-svn-id: http://code.djangoproject.com/svn/django/trunk@3077 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django')
-rw-r--r--django/contrib/humanize/templatetags/humanize.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/django/contrib/humanize/templatetags/humanize.py b/django/contrib/humanize/templatetags/humanize.py
index d3170f3116..b2d28a0ab4 100644
--- a/django/contrib/humanize/templatetags/humanize.py
+++ b/django/contrib/humanize/templatetags/humanize.py
@@ -48,3 +48,17 @@ def intword(value):
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)