publik: fix |first & |last on KeyError (#70954)
This commit is contained in:
parent
df0a449167
commit
a49ab97480
|
@ -63,7 +63,7 @@ def split(string, separator=' '):
|
||||||
def first(value):
|
def first(value):
|
||||||
try:
|
try:
|
||||||
return defaultfilters.first(value)
|
return defaultfilters.first(value)
|
||||||
except TypeError:
|
except (TypeError, KeyError):
|
||||||
return ''
|
return ''
|
||||||
|
|
||||||
|
|
||||||
|
@ -71,7 +71,7 @@ def first(value):
|
||||||
def last(value):
|
def last(value):
|
||||||
try:
|
try:
|
||||||
return defaultfilters.last(value)
|
return defaultfilters.last(value)
|
||||||
except TypeError:
|
except (TypeError, KeyError):
|
||||||
return ''
|
return ''
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -78,6 +78,9 @@ def test_first():
|
||||||
context = Context({'foo': None})
|
context = Context({'foo': None})
|
||||||
assert t.render(context) == ''
|
assert t.render(context) == ''
|
||||||
|
|
||||||
|
context = Context({'foo': {}})
|
||||||
|
assert t.render(context) == ''
|
||||||
|
|
||||||
|
|
||||||
def test_last():
|
def test_last():
|
||||||
t = Template('{{ foo|last }}')
|
t = Template('{{ foo|last }}')
|
||||||
|
@ -94,6 +97,9 @@ def test_last():
|
||||||
context = Context({'foo': None})
|
context = Context({'foo': None})
|
||||||
assert t.render(context) == ''
|
assert t.render(context) == ''
|
||||||
|
|
||||||
|
context = Context({'foo': {}})
|
||||||
|
assert t.render(context) == ''
|
||||||
|
|
||||||
|
|
||||||
def test_decimal():
|
def test_decimal():
|
||||||
tmpl = Template('{{ plop|decimal }}')
|
tmpl = Template('{{ plop|decimal }}')
|
||||||
|
|
Loading…
Reference in New Issue