Ticket #12554: r12819_with_tests.diff
File r12819_with_tests.diff, 2.7 KB (added by , 15 years ago) |
---|
-
django/template/__init__.py
570 570 if not lookup: 571 571 arg_vals.append(mark_safe(arg)) 572 572 else: 573 arg_vals.append(arg.resolve(context)) 573 try: 574 arg_vals.append(arg.resolve(context)) 575 except VariableDoesNotExist: 576 arg_vals.append(settings.TEMPLATE_STRING_IF_INVALID) 574 577 if getattr(func, 'needs_autoescape', False): 575 578 new_obj = func(obj, autoescape=context.autoescape, *arg_vals) 576 579 else: … … 745 748 TypeError, # unsubscriptable object 746 749 ): 747 750 raise VariableDoesNotExist("Failed lookup for key [%s] in %r", (bit, current)) # missing attribute 748 749 750 751 752 751 except Exception, e: 752 if getattr(e, 'silent_variable_failure', False): 753 current = settings.TEMPLATE_STRING_IF_INVALID 754 else: 755 raise 753 756 754 757 return current 755 758 -
tests/regressiontests/templates/tests.py
97 97 def method(self): 98 98 return "OtherClass.method" 99 99 100 class SilentGetItemClass(object): 101 def __getitem__(self, key): 102 raise SomeException 103 100 104 class UTF8Class: 101 105 "Class whose __str__ returns non-ASCII data" 102 106 def __str__(self): … … 552 556 #filters should accept empty string constants 553 557 'filter-syntax20': ('{{ ""|default_if_none:"was none" }}', {}, ""), 554 558 559 # regression tests for ticket #12554 560 'filter-syntax21': ("{{ a.b }}", {'a': SilentGetItemClass()}, ('', 'INVALID')), 561 'filter-syntax22': ("{{ a|default:notreal }}", {'a': 'test'}, ('test', 'test')), 562 'filter-syntax23': ("{{ a|default:notreal }}", {'a': ''}, ('', 'INVALID')), 563 555 564 ### COMMENT SYNTAX ######################################################## 556 565 'comment-syntax01': ("{# this is hidden #}hello", {}, "hello"), 557 566 'comment-syntax02': ("{# this is hidden #}hello{# foo #}", {}, "hello"),