Ticket #1903: get-patch.diff
File get-patch.diff, 1.4 KB (added by , 19 years ago) |
---|
-
django/template/defaultfilters.py
246 246 "Returns a random item from the list" 247 247 return random_module.choice(value) 248 248 249 def 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 249 256 def slice_(value, arg): 250 257 """ 251 258 Returns a slice of the list. … … 473 480 register.filter(removetags) 474 481 register.filter(random) 475 482 register.filter(rjust) 483 register.filter(get) 476 484 register.filter('slice', slice_) 477 485 register.filter(slugify) 478 486 register.filter(stringformat) -
tests/othertests/defaultfilters.py
173 173 >>> length_is('a', 10) 174 174 False 175 175 176 >>> get([1, 2, 3], 0) 177 1 178 179 >>> get([1, 2, 3], 1) 180 2 181 182 >>> get([1, 2, 3], 2) 183 3 184 185 >>> get([1, 2, 3], 3) 186 [1, 2, 3] 187 188 >>> get({'a': 1, 'c': 3, 'e': 5}, 'a') 189 1 190 191 >>> get({'a': 1, 'c': 3, 'e': 5}, 'c') 192 3 193 194 >>> get({'a': 1, 'c': 3, 'e': 5}, 'e') 195 5 196 197 >>> get({'a': 1, 'c': 3, 'e': 5}, 'g') 198 {'a': 1, 'c': 3, 'e': 5} 199 176 200 >>> slice_('abcdefg', '0') 177 201 ''