Ticket #2202: optional_argument_to_pluralize_template_filter.diff
File optional_argument_to_pluralize_template_filter.diff, 905 bytes (added by , 18 years ago) |
---|
-
django/template/defaultfilters.py
418 418 return "%.1f MB" % (bytes / (1024 * 1024)) 419 419 return "%.1f GB" % (bytes / (1024 * 1024 * 1024)) 420 420 421 def pluralize(value ):421 def pluralize(value, arg='s'): 422 422 "Returns 's' if the value is not 1, for '1 vote' vs. '2 votes'" 423 423 try: 424 424 if int(value) != 1: 425 return 's'425 return arg 426 426 except ValueError: # invalid string that's not a number 427 427 pass 428 428 except TypeError: # value isn't a string or a number; maybe it's a list? 429 429 try: 430 430 if len(value) != 1: 431 return 's'431 return arg 432 432 except TypeError: # len() of unsized object 433 433 pass 434 434 return ''