Ticket #3753: 3753-1.diff
File 3753-1.diff, 4.2 KB (added by , 18 years ago) |
---|
-
django/template/__init__.py
99 99 # global list of libraries to load by default for a new parser 100 100 builtins = [] 101 101 102 # a boolean for if TEMPLATE_STRING_IF_INVALID contains a format string (%s) 103 invalid_var_format_string = '%s' in settings.TEMPLATE_STRING_IF_INVALID 104 102 105 class TemplateSyntaxError(Exception): 103 106 def __str__(self): 104 107 try: … … 575 578 obj = None 576 579 else: 577 580 if settings.TEMPLATE_STRING_IF_INVALID: 581 if invalid_var_format_string: 582 return settings.TEMPLATE_STRING_IF_INVALID % self.var 578 583 return settings.TEMPLATE_STRING_IF_INVALID 579 584 else: 580 585 obj = settings.TEMPLATE_STRING_IF_INVALID -
tests/regressiontests/templates/tests.py
586 586 'invalidstr03': ('{% for v in var %}({{ v }}){% endfor %}', {}, ''), 587 587 'invalidstr04': ('{% if var %}Yes{% else %}No{% endif %}', {}, 'No'), 588 588 'invalidstr04': ('{% if var|default:"Foo" %}Yes{% else %}No{% endif %}', {}, 'Yes'), 589 'invalidstr05': ('{{ var }}', {}, ('', 'INVALID %s', 'var')), 590 'invalidstr06': ('{{ var.prop }}', {'var': {}}, ('', 'INVALID %s', 'var.prop')), 589 591 590 592 ### MULTILINE ############################################################# 591 593 … … 737 739 738 740 # Set TEMPLATE_STRING_IF_INVALID to a known string 739 741 old_invalid = settings.TEMPLATE_STRING_IF_INVALID 742 expected_invalid_str = 'INVALID' 740 743 741 744 for name, vals in tests: 742 745 install() … … 744 747 if isinstance(vals[2], tuple): 745 748 normal_string_result = vals[2][0] 746 749 invalid_string_result = vals[2][1] 750 if '%s' in invalid_string_result: 751 expected_invalid_str = 'INVALID %s' 752 invalid_string_result = invalid_string_result % vals[2][2] 753 template.invalid_var_format_string = True 747 754 else: 748 755 normal_string_result = vals[2] 749 756 invalid_string_result = vals[2] … … 754 761 activate('en-us') 755 762 756 763 for invalid_str, result in [('', normal_string_result), 757 ( 'INVALID', invalid_string_result)]:764 (expected_invalid_str, invalid_string_result)]: 758 765 settings.TEMPLATE_STRING_IF_INVALID = invalid_str 759 766 try: 760 767 output = loader.get_template(name).render(template.Context(vals[1])) … … 768 775 if 'LANGUAGE_CODE' in vals[1]: 769 776 deactivate() 770 777 778 if template.invalid_var_format_string: 779 expected_invalid_str = 'INVALID' 780 template.invalid_var_format_string = False 781 771 782 loader.template_source_loaders = old_template_loaders 772 783 deactivate() 773 784 settings.TEMPLATE_DEBUG = old_td -
AUTHORS
145 145 lerouxb@gmail.com 146 146 Waylan Limberg <waylan@gmail.com> 147 147 limodou 148 mattmcc148 Matt McClanahan <cardinal@dodds.net> 149 149 Martin Maney <http://www.chipy.org/Martin_Maney> 150 150 masonsimon+django@gmail.com 151 151 Manuzhai -
docs/templates_python.txt
212 212 tags, the variable will be interpreted as ``None``. Filters are always 213 213 applied to invalid variables within these template tags. 214 214 215 If TEMPLATE_STRING_IF_INVALID contains a ``'%s'``, it will be replaced with 216 the name of the invalid variable. 217 215 218 .. admonition:: For debug purposes only! 216 219 217 220 While ``TEMPLATE_STRING_IF_INVALID`` can be a useful debugging tool,