1
0
mirror of https://github.com/django/django.git synced 2025-07-04 09:49:12 +00:00

unicode: Audited humanize app for unicode compliance.

git-svn-id: http://code.djangoproject.com/svn/django/branches/unicode@5258 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Malcolm Tredinnick 2007-05-16 14:45:58 +00:00
parent 1ca5bc0f0c
commit 095d3ca8eb

View File

@ -1,4 +1,5 @@
from django.utils.translation import ungettext, ugettext_lazy as _ from django.utils.translation import ungettext, ugettext_lazy as _
from django.utils.encoding import smart_unicode
from django import template from django import template
import re import re
@ -15,8 +16,8 @@ def ordinal(value):
return value return value
t = (_('th'), _('st'), _('nd'), _('rd'), _('th'), _('th'), _('th'), _('th'), _('th'), _('th')) t = (_('th'), _('st'), _('nd'), _('rd'), _('th'), _('th'), _('th'), _('th'), _('th'), _('th'))
if value % 100 in (11, 12, 13): # special case if value % 100 in (11, 12, 13): # special case
return "%d%s" % (value, t[0]) return u"%d%s" % (value, t[0])
return '%d%s' % (value, t[value % 10]) return u'%d%s' % (value, t[value % 10])
register.filter(ordinal) register.filter(ordinal)
def intcomma(value): def intcomma(value):
@ -24,8 +25,8 @@ def intcomma(value):
Converts an integer to a string containing commas every three digits. Converts an integer to a string containing commas every three digits.
For example, 3000 becomes '3,000' and 45000 becomes '45,000'. For example, 3000 becomes '3,000' and 45000 becomes '45,000'.
""" """
orig = str(value) orig = smart_unicode(value)
new = re.sub("^(-?\d+)(\d{3})", '\g<1>,\g<2>', str(value)) new = re.sub("^(-?\d+)(\d{3})", '\g<1>,\g<2>', smart_unicode(value))
if orig == new: if orig == new:
return new return new
else: else: