diff options
| author | Malcolm Tredinnick <malcolm.tredinnick@gmail.com> | 2009-03-25 03:45:56 +0000 |
|---|---|---|
| committer | Malcolm Tredinnick <malcolm.tredinnick@gmail.com> | 2009-03-25 03:45:56 +0000 |
| commit | 2c6c60cec613246bff5cb0be831969c20417b53c (patch) | |
| tree | 01d35083c3c84236cd460b83512b432a794eef5c /django/template/__init__.py | |
| parent | 7f63d0009f762c6ce1c665df3674be2fcd3ef7fa (diff) | |
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
Diffstat (limited to 'django/template/__init__.py')
| -rw-r--r-- | django/template/__init__.py | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/django/template/__init__.py b/django/template/__init__.py index c5b8ba0b8f..503cfb77bf 100644 --- a/django/template/__init__.py +++ b/django/template/__init__.py @@ -445,16 +445,17 @@ class TokenParser(object): self.pointer = i return s +# This only matches constant *strings* (things in quotes or marked for +# translation). Numbers are treated as variables for implementation reasons +# (so that they retain their type when passed to filters). constant_string = r""" (?:%(i18n_open)s%(strdq)s%(i18n_close)s| %(i18n_open)s%(strsq)s%(i18n_close)s| %(strdq)s| -%(strsq)s)| -%(num)s +%(strsq)s) """ % { 'strdq': r'"[^"\\]*(?:\\.[^"\\]*)*"', # double-quoted string 'strsq': r"'[^'\\]*(?:\\.[^'\\]*)*'", # single-quoted string - 'num': r'[-+\.]?\d[\d\.e]*', # numeric constant 'i18n_open' : re.escape("_("), 'i18n_close' : re.escape(")"), } @@ -462,17 +463,18 @@ constant_string = constant_string.replace("\n", "") filter_raw_string = r""" ^(?P<constant>%(constant)s)| -^(?P<var>[%(var_chars)s]+)| +^(?P<var>[%(var_chars)s]+|%(num)s)| (?:%(filter_sep)s (?P<filter_name>\w+) (?:%(arg_sep)s (?: (?P<constant_arg>%(constant)s)| - (?P<var_arg>[%(var_chars)s]+) + (?P<var_arg>[%(var_chars)s]+|%(num)s) ) )? )""" % { 'constant': constant_string, + 'num': r'[-+\.]?\d[\d\.e]*', 'var_chars': "\w\." , 'filter_sep': re.escape(FILTER_SEPARATOR), 'arg_sep': re.escape(FILTER_ARGUMENT_SEPARATOR), |
