id,summary,reporter,owner,description,type,status,component,version,severity,resolution,keywords,cc,stage,has_patch,needs_docs,needs_tests,needs_better_patch,easy,ui_ux 365,[patch] Change template.resolve_variable() to resolve hard-coded strings,davidschein@…,Adrian Holovaty,"Change {% ifnotequal %} tag to accept hard-coded strings. i.e. {% ifnotequal app.name 'Core' %} ... {% endifnotequal %} The following patch basically just adds: if path[0]==path[-1] and path[0] in ['""', ""'""]: return path[1:-1] but using a wrapping conditional instead of seperate returns. {{{ Index: template.py =================================================================== --- template.py (revision 532) +++ template.py (working copy) @@ -369,30 +369,33 @@ (The example assumes VARIABLE_ATTRIBUTE_SEPARATOR is '.') """""" - current = context - bits = path.split(VARIABLE_ATTRIBUTE_SEPARATOR) - while bits: - try: # dictionary lookup - current = current[bits[0]] - except (TypeError, AttributeError, KeyError): - try: # attribute lookup - current = getattr(current, bits[0]) - if callable(current): - if getattr(current, 'alters_data', False): - current = '' - else: - try: # method call (assuming no args required) - current = current() - except SilentVariableFailure: + if path[0]==path[-1] and path[0] in ['""', ""'""]: #it's a hard-coded string + current = path[1:-1] + else: + current = context + bits = path.split(VARIABLE_ATTRIBUTE_SEPARATOR) + while bits: + try: # dictionary lookup + current = current[bits[0]] + except (TypeError, AttributeError, KeyError): + try: # attribute lookup + current = getattr(current, bits[0]) + if callable(current): + if getattr(current, 'alters_data', False): current = '' - except TypeError: # arguments *were* required - current = '' # invalid method call - except (TypeError, AttributeError): - try: # list-index lookup - current = current[int(bits[0])] - except (IndexError, ValueError, KeyError): - raise VariableDoesNotExist, ""Failed lookup for key [%s] in %r"" % (bits[0], current) # missing attribute - del bits[0] + else: + try: # method call (assuming no args required) + current = current() + except SilentVariableFailure: + current = '' + except TypeError: # arguments *were* required + current = '' # invalid method call + except (TypeError, AttributeError): + try: # list-index lookup + current = current[int(bits[0])] + except (IndexError, ValueError, KeyError): + raise VariableDoesNotExist, ""Failed lookup for key [%s] in %r"" % (bits[0], current) # missing attribute + del bits[0] return current def resolve_variable_with_filters(var_string, context): }}}",defect,closed,Template system,,minor,fixed,tag ifnotequal,,Unreviewed,1,0,0,0,0,0