Ticket #3753: 3753-2.diff

File 3753-2.diff, 4.2 KB (added by Matt McClanahan <cardinal@…>, 17 years ago)

Rather use URL than email

  • django/template/__init__.py

     
    9999# global list of libraries to load by default for a new parser
    100100builtins = []
    101101
     102# a boolean for if TEMPLATE_STRING_IF_INVALID contains a format string (%s)
     103invalid_var_format_string = '%s' in settings.TEMPLATE_STRING_IF_INVALID
     104
    102105class TemplateSyntaxError(Exception):
    103106    def __str__(self):
    104107        try:
     
    575578                obj = None
    576579            else:
    577580                if settings.TEMPLATE_STRING_IF_INVALID:
     581                    if invalid_var_format_string:
     582                        return settings.TEMPLATE_STRING_IF_INVALID % self.var
    578583                    return settings.TEMPLATE_STRING_IF_INVALID
    579584                else:
    580585                    obj = settings.TEMPLATE_STRING_IF_INVALID
  • tests/regressiontests/templates/tests.py

     
    586586            'invalidstr03': ('{% for v in var %}({{ v }}){% endfor %}', {}, ''),
    587587            'invalidstr04': ('{% if var %}Yes{% else %}No{% endif %}', {}, 'No'),
    588588            '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')),
    589591
    590592            ### MULTILINE #############################################################
    591593
     
    737739
    738740        # Set TEMPLATE_STRING_IF_INVALID to a known string
    739741        old_invalid = settings.TEMPLATE_STRING_IF_INVALID
     742        expected_invalid_str = 'INVALID'
    740743
    741744        for name, vals in tests:
    742745            install()
     
    744747            if isinstance(vals[2], tuple):
    745748                normal_string_result = vals[2][0]
    746749                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
    747754            else:
    748755                normal_string_result = vals[2]
    749756                invalid_string_result = vals[2]
     
    754761                activate('en-us')
    755762
    756763            for invalid_str, result in [('', normal_string_result),
    757                                         ('INVALID', invalid_string_result)]:
     764                                        (expected_invalid_str, invalid_string_result)]:
    758765                settings.TEMPLATE_STRING_IF_INVALID = invalid_str
    759766                try:
    760767                    output = loader.get_template(name).render(template.Context(vals[1]))
     
    768775            if 'LANGUAGE_CODE' in vals[1]:
    769776                deactivate()
    770777
     778            if template.invalid_var_format_string:
     779                expected_invalid_str = 'INVALID'
     780                template.invalid_var_format_string = False
     781
    771782        loader.template_source_loaders = old_template_loaders
    772783        deactivate()
    773784        settings.TEMPLATE_DEBUG = old_td
  • AUTHORS

     
    145145    lerouxb@gmail.com
    146146    Waylan Limberg <waylan@gmail.com>
    147147    limodou
    148     mattmcc
     148    Matt McClanahan <http://mmcc.cx/>
    149149    Martin Maney <http://www.chipy.org/Martin_Maney>
    150150    masonsimon+django@gmail.com
    151151    Manuzhai
  • docs/templates_python.txt

     
    212212tags, the variable will be interpreted as ``None``. Filters are always
    213213applied to invalid variables within these template tags.
    214214
     215If TEMPLATE_STRING_IF_INVALID contains a ``'%s'``, it will be replaced with
     216the name of the invalid variable.
     217
    215218.. admonition:: For debug purposes only!
    216219
    217220    While ``TEMPLATE_STRING_IF_INVALID`` can be a useful debugging tool,
Back to Top