Permalink
Browse files

Used the decorator syntax consistently to register template filters.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@17052 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
1 parent 345be05 commit 52c66a21e1b2d790f12da6e05e10142397998d31 @aaugustin aaugustin committed Oct 29, 2011
@@ -9,10 +9,9 @@
from django.utils.translation import pgettext, ungettext, ugettext as _
from django.utils.tzinfo import LocalTimezone
-
register = template.Library()
-
+@register.filter
def ordinal(value):
"""
Converts an integer to its ordinal as a string. 1 is '1st', 2 is '2nd',
@@ -27,8 +26,8 @@ def ordinal(value):
return u"%d%s" % (value, suffixes[0])
return u"%d%s" % (value, suffixes[value % 10])
ordinal.is_safe = True
-register.filter(ordinal)
+@register.filter
def intcomma(value, use_l10n=True):
"""
Converts an integer to a string containing commas every three digits.
@@ -49,7 +48,6 @@ def intcomma(value, use_l10n=True):
else:
return intcomma(new, use_l10n)
intcomma.is_safe = True
-register.filter(intcomma)
# A tuple of standard large number to their converters
intword_converters = (
@@ -99,6 +97,7 @@ def intcomma(value, use_l10n=True):
)),
)
+@register.filter
def intword(value):
"""
Converts a large integer to a friendly text representation. Works best
@@ -131,8 +130,8 @@ def _check_for_i18n(value, float_formatted, string_formatted):
return _check_for_i18n(new_value, *converters(new_value))
return value
intword.is_safe = False
-register.filter(intword)
+@register.filter
def apnumber(value):
"""
For numbers 1-9, returns the number spelled out. Otherwise, returns the
@@ -146,7 +145,6 @@ def apnumber(value):
return value
return (_('one'), _('two'), _('three'), _('four'), _('five'), _('six'), _('seven'), _('eight'), _('nine'))[value-1]
apnumber.is_safe = True
-register.filter(apnumber)
@register.filter
def naturalday(value, arg=None):
@@ -18,6 +18,7 @@
register = template.Library()
+@register.filter
def textile(value):
try:
import textile
@@ -29,6 +30,7 @@ def textile(value):
return mark_safe(force_unicode(textile.textile(smart_str(value), encoding='utf-8', output='utf-8')))
textile.is_safe = True
+@register.filter
def markdown(value, arg=''):
"""
Runs Markdown over a given value, optionally using various
@@ -73,6 +75,7 @@ def markdown(value, arg=''):
return mark_safe(force_unicode(markdown.markdown(smart_str(value))))
markdown.is_safe = True
+@register.filter
def restructuredtext(value):
try:
from docutils.core import publish_parts
@@ -86,6 +89,3 @@ def restructuredtext(value):
return mark_safe(force_unicode(parts["fragment"]))
restructuredtext.is_safe = True
-register.filter(textile)
-register.filter(markdown)
-register.filter(restructuredtext)
Oops, something went wrong.

0 comments on commit 52c66a2

Please sign in to comment.