Changeset 9442
- Timestamp:
- 11/14/08 19:16:20 (2 months ago)
- Files:
-
- django/trunk/django/template/defaultfilters.py (modified) (4 diffs)
- django/trunk/tests/regressiontests/templates/filters.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/trunk/django/template/defaultfilters.py
r9369 r9442 100 100 # Values for testing floatformat input against infinity and NaN representations, 101 101 # which differ across platforms and Python versions. Some (i.e. old Windows 102 # ones) are not recognized by Decimal but we want to return them unchanged vs. 102 # ones) are not recognized by Decimal but we want to return them unchanged vs. 103 103 # returning an empty string as we do for completley invalid input. Note these 104 # need to be built up from values that are not inf/nan, since inf/nan values do 105 # not reload properly from .pyc files on Windows prior to some level of Python 2.5 104 # need to be built up from values that are not inf/nan, since inf/nan values do 105 # not reload properly from .pyc files on Windows prior to some level of Python 2.5 106 106 # (see Python Issue757815 and Issue1080440). 107 107 pos_inf = 1e200 * 1e200 … … 137 137 * {{ num2|floatformat:"-3" }} displays "34" 138 138 * {{ num3|floatformat:"-3" }} displays "34.260" 139 139 140 140 If the input float is infinity or NaN, the (platform-dependent) string 141 141 representation of that value will be displayed. 142 142 """ 143 143 144 144 try: 145 145 input_val = force_unicode(text) … … 156 156 except ValueError: 157 157 return input_val 158 158 159 159 try: 160 160 m = int(d) - d 161 161 except (OverflowError, InvalidOperation): 162 162 return input_val 163 163 164 164 if not m and p < 0: 165 165 return mark_safe(u'%d' % (int(d))) 166 166 167 167 if p == 0: 168 168 exp = Decimal(1) … … 482 482 first.is_safe = False 483 483 484 def join(value, arg): 485 """Joins a list with a string, like Python's ``str.join(list)``.""" 486 try: 487 data = arg.join(map(force_unicode, value)) 484 def join(value, arg, autoescape=None): 485 """ 486 Joins a list with a string, like Python's ``str.join(list)``. 487 """ 488 if autoescape: 489 from django.utils.html import conditional_escape 490 value = [conditional_escape(v) for v in value] 491 try: 492 data = arg.join(value) 488 493 except AttributeError: # fail silently but nicely 489 494 return value 490 safe_args = reduce(lambda lhs, rhs: lhs and isinstance(rhs, SafeData), 491 value, True) 492 if safe_args: 493 return mark_safe(data) 494 else: 495 return data 495 return mark_safe(data) 496 496 join.is_safe = True 497 join.needs_autoescape = True 497 498 498 499 def last(value): django/trunk/tests/regressiontests/templates/filters.py
r9291 r9442 278 278 'escapejs01': (r'{{ a|escapejs }}', {'a': 'testing\r\njavascript \'string" <b>escaping</b>'}, 'testing\\x0D\\x0Ajavascript \\x27string\\x22 \\x3Cb\\x3Eescaping\\x3C/b\\x3E'), 279 279 'escapejs02': (r'{% autoescape off %}{{ a|escapejs }}{% endautoescape %}', {'a': 'testing\r\njavascript \'string" <b>escaping</b>'}, 'testing\\x0D\\x0Ajavascript \\x27string\\x22 \\x3Cb\\x3Eescaping\\x3C/b\\x3E'), 280 280 281 281 # Boolean return value from length_is should not be coerced to a string 282 282 'lengthis01': (r'{% if "X"|length_is:0 %}Length is 0{% else %}Length not 0{% endif %}', {}, 'Length not 0'), 283 283 'lengthis02': (r'{% if "X"|length_is:1 %}Length is 1{% else %}Length not 1{% endif %}', {}, 'Length is 1'), 284 285 'join01': (r'{{ a|join:", " }}', {'a': ['alpha', 'beta & me']}, 'alpha, beta & me'), 286 'join02': (r'{% autoescape off %}{{ a|join:", " }}{% endautoescape %}', {'a': ['alpha', 'beta & me']}, 'alpha, beta & me'), 287 'join03': (r'{{ a|join:" & " }}', {'a': ['alpha', 'beta & me']}, 'alpha & beta & me'), 288 'join04': (r'{% autoescape off %}{{ a|join:" & " }}{% endautoescape %}', {'a': ['alpha', 'beta & me']}, 'alpha & beta & me'), 284 289 } 285 290
