Ticket #5567: filter-last.2.diff

File filter-last.2.diff, 1.3 KB (added by Aaron C. de Bruyn, 17 years ago)
  • django/template/defaultfilters.py

     
    431431        return value[0]
    432432    except IndexError:
    433433        return u''
    434 first.is_safe = True
     434first.is_safe = False
    435435
     436def last(value):
     437    "Returns the last item in a list"
     438    try:
     439        return value[-1]
     440    except IndexError:
     441        return u''
     442last.is_safe = False
     443
    436444def join(value, arg):
    437445    """Joins a list with a string, like Python's ``str.join(list)``."""
    438446    try:
  • tests/regressiontests/defaultfilters/tests.py

     
    508508u'123'
    509509>>> striptags(123)
    510510u'123'
     511>>> last([0, 1, 2, 3, 4])
     5124
     513>>> last(u'Hello')
     514u'o'
    511515
    512516"""
    513517
  • docs/templates.txt

     
    14031403
    14041404Joins a list with a string, like Python's ``str.join(list)``.
    14051405
     1406last
     1407~~~~
     1408
     1409Returns the last item in a list.
     1410
    14061411length
    14071412~~~~~~
    14081413
Back to Top