Ticket #1903: get-patch.diff

File get-patch.diff, 1.4 KB (added by erickt@…, 19 years ago)

adding the .diff extension to get highlighting working

  • django/template/defaultfilters.py

     
    246246    "Returns a random item from the list"
    247247    return random_module.choice(value)
    248248
     249def get(value, arg):
     250    "Returns an item from an idexable item"
     251    try:
     252        return value[arg]
     253    except LookupError:
     254        return value # Fail silently.
     255
    249256def slice_(value, arg):
    250257    """
    251258    Returns a slice of the list.
     
    473480register.filter(removetags)
    474481register.filter(random)
    475482register.filter(rjust)
     483register.filter(get)
    476484register.filter('slice', slice_)
    477485register.filter(slugify)
    478486register.filter(stringformat)
  • tests/othertests/defaultfilters.py

     
    173173>>> length_is('a', 10)
    174174False
    175175
     176>>> get([1, 2, 3], 0)
     1771
     178
     179>>> get([1, 2, 3], 1)
     1802
     181
     182>>> get([1, 2, 3], 2)
     1833
     184
     185>>> get([1, 2, 3], 3)
     186[1, 2, 3]
     187
     188>>> get({'a': 1, 'c': 3, 'e': 5}, 'a')
     1891
     190
     191>>> get({'a': 1, 'c': 3, 'e': 5}, 'c')
     1923
     193
     194>>> get({'a': 1, 'c': 3, 'e': 5}, 'e')
     1955
     196
     197>>> get({'a': 1, 'c': 3, 'e': 5}, 'g')
     198{'a': 1, 'c': 3, 'e': 5}
     199
    176200>>> slice_('abcdefg', '0')
    177201''
Back to Top