Ticket #1684: defaultfilters.diff

File defaultfilters.diff, 917 bytes (added by James Bennett, 19 years ago)

patch against magic-removal to add 'numerize' filter

  • defaultfilters.py

     
    6363    """
    6464    return list(str(value))
    6565
     66def numerize(num):
     67    """
     68    For numbers 1-9, returns the number spelled out. Otherwise, returns
     69    the number.
     70    """
     71    if type(num) is not int or not 0 < num < 10:
     72        return num
     73    as_words = ['one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine']
     74    return as_words[num-1]
     75
    6676def slugify(value):
    6777    "Converts to lowercase, removes non-alpha chars and converts spaces to hyphens"
    6878    value = re.sub('[^\w\s-]', '', value).strip().lower()
     
    463473register.filter(ljust)
    464474register.filter(lower)
    465475register.filter(make_list)
     476register.filter(numerize)
    466477register.filter(phone2numeric)
    467478register.filter(pluralize)
    468479register.filter(pprint)
Back to Top