diff options
| author | Malcolm Tredinnick <malcolm.tredinnick@gmail.com> | 2007-07-04 09:28:29 +0000 |
|---|---|---|
| committer | Malcolm Tredinnick <malcolm.tredinnick@gmail.com> | 2007-07-04 09:28:29 +0000 |
| commit | 5664a678b29ab04cad425c15b2792f4519f43928 (patch) | |
| tree | 7e8ef34cb859f3deb73872abc20aa50499dde4df /django/template | |
| parent | 216fae2352871e04e8edd44045c63bf5379ab229 (diff) | |
unicode: Added unicode-aware slugify filter (in Python) and better non-ASCIIarchive/attic/unicode
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.
git-svn-id: http://code.djangoproject.com/svn/django/branches/unicode@5608 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/template')
| -rw-r--r-- | django/template/defaultfilters.py | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/django/template/defaultfilters.py b/django/template/defaultfilters.py index 6effac184f..6aadbf2381 100644 --- a/django/template/defaultfilters.py +++ b/django/template/defaultfilters.py @@ -115,10 +115,13 @@ def make_list(value): make_list = stringfilter(make_list) def slugify(value): - "Converts to lowercase, removes non-alpha chars and converts spaces to hyphens" - # Don't compile patterns as unicode because \w then would mean any letter. - # Slugify is effectively a conversion to ASCII. - value = re.sub('[^\w\s-]', '', value).strip().lower() + """ + Normalizes string, converts to lowercase, removes non-alpha chars and + converts spaces to hyphens. + """ + import unicodedata + value = unicodedata.normalize('NFKD', value).encode('ascii', 'ignore') + value = unicode(re.sub('[^\w\s-]', '', value).strip().lower()) return re.sub('[-\s]+', '-', value) slugify = stringfilter(slugify) |
