Ticket #2202: optional_argument_to_pluralize_template_filter.diff

File optional_argument_to_pluralize_template_filter.diff, 905 bytes (added by gid <setre3+django@…>, 18 years ago)
  • django/template/defaultfilters.py

     
    418418        return "%.1f MB" % (bytes / (1024 * 1024))
    419419    return "%.1f GB" % (bytes / (1024 * 1024 * 1024))
    420420
    421 def pluralize(value):
     421def pluralize(value, arg='s'):
    422422    "Returns 's' if the value is not 1, for '1 vote' vs. '2 votes'"
    423423    try:
    424424        if int(value) != 1:
    425             return 's'
     425            return arg
    426426    except ValueError: # invalid string that's not a number
    427427        pass
    428428    except TypeError: # value isn't a string or a number; maybe it's a list?
    429429        try:
    430430            if len(value) != 1:
    431                 return 's'
     431                return arg
    432432        except TypeError: # len() of unsized object
    433433            pass
    434434    return ''
Back to Top