publik: add |last template filter (#66955)
This commit is contained in:
parent
fae07a449e
commit
c71350052e
|
@ -54,3 +54,11 @@ def first(value):
|
|||
return defaultfilters.first(value)
|
||||
except TypeError:
|
||||
return ''
|
||||
|
||||
|
||||
@register.filter
|
||||
def last(value):
|
||||
try:
|
||||
return defaultfilters.last(value)
|
||||
except TypeError:
|
||||
return ''
|
||||
|
|
|
@ -68,3 +68,19 @@ def test_first():
|
|||
|
||||
context = Context({'foo': None})
|
||||
assert t.render(context) == ''
|
||||
|
||||
|
||||
def test_last():
|
||||
t = Template('{{ foo|last }}')
|
||||
|
||||
context = Context({'foo': ['foo']})
|
||||
assert t.render(context) == 'foo'
|
||||
|
||||
context = Context({'foo': 'foo'})
|
||||
assert t.render(context) == 'o'
|
||||
|
||||
context = Context({'foo': ''})
|
||||
assert t.render(context) == ''
|
||||
|
||||
context = Context({'foo': None})
|
||||
assert t.render(context) == ''
|
||||
|
|
Loading…
Reference in New Issue