Ticket #4365: defaultfilters.py.patch

File defaultfilters.py.patch, 770 bytes (added by Jonas von Poser, 17 years ago)

Normallizes string

  • django/template/defaultfilters.py

     
    120120make_list = stringfilter(make_list)
    121121
    122122def slugify(value):
    123     "Converts to lowercase, removes non-alpha chars and converts spaces to hyphens"
    124     value = re.sub('[^\w\s-]', '', value).strip().lower()
     123    """Normalizes string, converts to lowercase, removes non-alpha chars
     124    and converts spaces to hyphens."""
     125    import unicodedata
     126    ascii_str = unicodedata.normalize( 'NFKD', \
     127        value.decode('utf-8', 'replace') ).encode('ascii', 'ignore')
     128    value = re.sub('[^\w\s-]', '', ascii_str).strip().lower()
    125129    return re.sub('[-\s]+', '-', value)
    126130slugify = stringfilter(slugify)
    127131
Back to Top