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):
|
||||
try:
|
||||
return defaultfilters.first(value)
|
||||
except TypeError:
|
||||
except (TypeError, KeyError):
|
||||
return ''
|
||||
|
||||
|
||||
|
@ -71,7 +71,7 @@ def first(value):
|
|||
def last(value):
|
||||
try:
|
||||
return defaultfilters.last(value)
|
||||
except TypeError:
|
||||
except (TypeError, KeyError):
|
||||
return ''
|
||||
|
||||
|
||||
|
|
|
@ -78,6 +78,9 @@ def test_first():
|
|||
context = Context({'foo': None})
|
||||
assert t.render(context) == ''
|
||||
|
||||
context = Context({'foo': {}})
|
||||
assert t.render(context) == ''
|
||||
|
||||
|
||||
def test_last():
|
||||
t = Template('{{ foo|last }}')
|
||||
|
@ -94,6 +97,9 @@ def test_last():
|
|||
context = Context({'foo': None})
|
||||
assert t.render(context) == ''
|
||||
|
||||
context = Context({'foo': {}})
|
||||
assert t.render(context) == ''
|
||||
|
||||
|
||||
def test_decimal():
|
||||
tmpl = Template('{{ plop|decimal }}')
|
||||
|
|
Loading…
Reference in New Issue