Changeset 5167
- Timestamp:
- 05/07/07 22:36:16 (1 year ago)
- Files:
-
- django/trunk/AUTHORS (modified) (1 diff)
- django/trunk/django/template/__init__.py (modified) (2 diffs)
- django/trunk/docs/templates_python.txt (modified) (1 diff)
- django/trunk/tests/regressiontests/templates/tests.py (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/trunk/AUTHORS
r5166 r5167 148 148 Waylan Limberg <waylan@gmail.com> 149 149 limodou 150 mattmcc150 Matt McClanahan <http://mmcc.cx/> 151 151 Martin Maney <http://www.chipy.org/Martin_Maney> 152 152 masonsimon+django@gmail.com django/trunk/django/template/__init__.py
r5117 r5167 99 99 # global list of libraries to load by default for a new parser 100 100 builtins = [] 101 102 # True if TEMPLATE_STRING_IF_INVALID contains a format string (%s). None means 103 # uninitialised. 104 invalid_var_format_string = None 101 105 102 106 class TemplateSyntaxError(Exception): … … 576 580 else: 577 581 if settings.TEMPLATE_STRING_IF_INVALID: 582 global invalid_var_format_string 583 if invalid_var_format_string is None: 584 invalid_var_format_string = '%s' in settings.TEMPLATE_STRING_IF_INVALID 585 if invalid_var_format_string: 586 return settings.TEMPLATE_STRING_IF_INVALID % self.var 578 587 return settings.TEMPLATE_STRING_IF_INVALID 579 588 else: django/trunk/docs/templates_python.txt
r5161 r5167 213 213 applied to invalid variables within these template tags. 214 214 215 If ``TEMPLATE_STRING_IF_INVALID`` contains a ``'%s'``, the format marker will 216 be replaced with the name of the invalid variable. 217 215 218 .. admonition:: For debug purposes only! 216 219 217 While ``TEMPLATE_STRING_IF_INVALID`` can be a useful debugging tool, 218 it is a bad idea to turn it on as a 'development default'. 220 While ``TEMPLATE_STRING_IF_INVALID`` can be a useful debugging tool, 221 it is a bad idea to turn it on as a 'development default'. 219 222 220 Many templates, including those in the Admin site, rely upon the 221 silence of the template system when a non-existent variable is 223 Many templates, including those in the Admin site, rely upon the 224 silence of the template system when a non-existent variable is 222 225 encountered. If you assign a value other than ``''`` to 223 ``TEMPLATE_STRING_IF_INVALID``, you will experience rendering 226 ``TEMPLATE_STRING_IF_INVALID``, you will experience rendering 224 227 problems with these templates and sites. 225 228 226 Generally, ``TEMPLATE_STRING_IF_INVALID`` should only be enabled 227 in order to debug a specific template problem, then cleared 229 Generally, ``TEMPLATE_STRING_IF_INVALID`` should only be enabled 230 in order to debug a specific template problem, then cleared 228 231 once debugging is complete. 229 232 230 233 Playing with Context objects 231 234 ---------------------------- django/trunk/tests/regressiontests/templates/tests.py
r5125 r5167 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 ############################################################# … … 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: … … 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] … … 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: … … 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()
