Django

Code

Show
Ignore:
Timestamp:
07/04/07 04:28:29 (2 years ago)
Author:
mtredinnick
Message:

unicode: Added unicode-aware slugify filter (in Python) and better non-ASCII
handling for the Javascript slug creator in admin. Can never be perfect here,
but this is more tolerant in many cases. Fixed #4365. Thanks, Bill de hÓra,
Baptiste, orestis@orestis.gr, Ahmet and Jonas for contributions to this.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/branches/unicode/django/template/defaultfilters.py

    r5597 r5608  
    116116 
    117117def slugify(value): 
    118     "Converts to lowercase, removes non-alpha chars and converts spaces to hyphens" 
    119     # Don't compile patterns as unicode because \w then would mean any letter. 
    120     # Slugify is effectively a conversion to ASCII. 
    121     value = re.sub('[^\w\s-]', '', value).strip().lower() 
     118    """ 
     119    Normalizes string, converts to lowercase, removes non-alpha chars and 
     120    converts spaces to hyphens. 
     121    """ 
     122    import unicodedata 
     123    value = unicodedata.normalize('NFKD', value).encode('ascii', 'ignore') 
     124    value = unicode(re.sub('[^\w\s-]', '', value).strip().lower()) 
    122125    return re.sub('[-\s]+', '-', value) 
    123126slugify = stringfilter(slugify)