mirror of
https://github.com/django/django.git
synced 2025-10-24 06:06:09 +00:00
Template filters now pass numerical arguments through as numbers.
This was the (undocumented) behaviour prior to r10118 and now it's back again. It's neither hard nor harmful to maintain compatibility with the old ways. git-svn-id: http://code.djangoproject.com/svn/django/trunk@10169 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
11
tests/regressiontests/templates/custom.py
Normal file
11
tests/regressiontests/templates/custom.py
Normal file
@@ -0,0 +1,11 @@
|
||||
from django import test
|
||||
from django import template
|
||||
|
||||
|
||||
custom_filters = """
|
||||
>>> t = template.Template("{% load custom %}{{ string|trim:5 }}")
|
||||
>>> ctxt = template.Context({"string": "abcdefghijklmnopqrstuvwxyz"})
|
||||
>>> t.render(ctxt)
|
||||
u"abcde"
|
||||
"""
|
||||
|
||||
11
tests/regressiontests/templates/templatetags/custom.py
Normal file
11
tests/regressiontests/templates/templatetags/custom.py
Normal file
@@ -0,0 +1,11 @@
|
||||
from django import template
|
||||
from django.template.defaultfilters import stringfilter
|
||||
|
||||
register = template.Library()
|
||||
|
||||
def trim(value, num):
|
||||
return value[:num]
|
||||
trim = stringfilter(trim)
|
||||
|
||||
register.filter(trim)
|
||||
|
||||
@@ -18,9 +18,10 @@ from django.utils.translation import activate, deactivate, ugettext as _
|
||||
from django.utils.safestring import mark_safe
|
||||
from django.utils.tzinfo import LocalTimezone
|
||||
|
||||
from unicode import unicode_tests
|
||||
from context import context_tests
|
||||
from custom import custom_filters
|
||||
from parser import filter_parsing, variable_parsing
|
||||
from unicode import unicode_tests
|
||||
|
||||
try:
|
||||
from loaders import *
|
||||
@@ -34,6 +35,7 @@ __test__ = {
|
||||
'unicode': unicode_tests,
|
||||
'context': context_tests,
|
||||
'filter_parsing': filter_parsing,
|
||||
'custom_filters': custom_filters,
|
||||
}
|
||||
|
||||
#################################
|
||||
|
||||
Reference in New Issue
Block a user