mirror of
https://github.com/django/django.git
synced 2025-10-24 14:16:09 +00:00
Fixes #2637 -- Clarified handling of TEMPLATE_STRING_IF_INVALID, especially with regards to filtering of invalid values. Modified unit tests to test both empty and non-empty values for TEMPLATE_STRING_IF_INVALID. Thanks to SmileyChris for identifying and helping to resolve this bug.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@3714 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
@@ -549,9 +549,12 @@ class FilterExpression(object):
|
||||
obj = resolve_variable(self.var, context)
|
||||
except VariableDoesNotExist:
|
||||
if ignore_failures:
|
||||
return None
|
||||
obj = None
|
||||
else:
|
||||
return settings.TEMPLATE_STRING_IF_INVALID
|
||||
if settings.TEMPLATE_STRING_IF_INVALID:
|
||||
return settings.TEMPLATE_STRING_IF_INVALID
|
||||
else:
|
||||
obj = settings.TEMPLATE_STRING_IF_INVALID
|
||||
for func, args in self.filters:
|
||||
arg_vals = []
|
||||
for lookup, arg in args:
|
||||
|
||||
@@ -86,7 +86,7 @@ class ForNode(Node):
|
||||
parentloop = {}
|
||||
context.push()
|
||||
try:
|
||||
values = self.sequence.resolve(context)
|
||||
values = self.sequence.resolve(context, True)
|
||||
except VariableDoesNotExist:
|
||||
values = []
|
||||
if values is None:
|
||||
@@ -212,13 +212,13 @@ class RegroupNode(Node):
|
||||
self.var_name = var_name
|
||||
|
||||
def render(self, context):
|
||||
obj_list = self.target.resolve(context)
|
||||
if obj_list == '': # target_var wasn't found in context; fail silently
|
||||
obj_list = self.target.resolve(context, True)
|
||||
if obj_list == None: # target_var wasn't found in context; fail silently
|
||||
context[self.var_name] = []
|
||||
return ''
|
||||
output = [] # list of dictionaries in the format {'grouper': 'key', 'list': [list of contents]}
|
||||
for obj in obj_list:
|
||||
grouper = self.expression.resolve(Context({'var': obj}))
|
||||
grouper = self.expression.resolve(Context({'var': obj}), True)
|
||||
# TODO: Is this a sensible way to determine equality?
|
||||
if output and repr(output[-1]['grouper']) == repr(grouper):
|
||||
output[-1]['list'].append(obj)
|
||||
|
||||
Reference in New Issue
Block a user