Ticket #5567: last_and_nth_filters.diff
File last_and_nth_filters.diff, 1.1 KB (added by , 17 years ago) |
---|
-
django/template/defaultfilters.py
320 320 except IndexError: 321 321 return u'' 322 322 323 def last(value): 324 "Returns the last item in a list" 325 try: 326 return value[-1] 327 except IndexError: 328 return u'' 329 330 def nth(value, arg): 331 "Returns the nth item in a list" 332 try: 333 return value[int(arg)] 334 except IndexError: 335 return u'' 336 323 337 def join(value, arg): 324 338 "Joins a list with a string, like Python's ``str.join(list)``" 325 339 try: -
tests/regressiontests/defaultfilters/tests.py
490 490 u'123' 491 491 >>> striptags(123) 492 492 u'123' 493 493 >>> last([0, 1, 2, 3, 4]) 494 4 495 >>> last(u'Hello') 496 u'o' 497 >>> nth(['a', 'b', 'c', 'd'], 1) 498 'b' 499 >>> nth(u'abcd', 1) 500 u'b' 494 501 """ 495 502 496 503 from django.template.defaultfilters import *