Commits

David Chambers committed b4b816f

Switched from `django.template.defaultfilters.slugify` to a custom function,
`mango.utils.slugify`, for slugifying tag names. Full stops are now preserved
as a result ("Terminal.app" → "terminal.app" not "terminalapp").

Comments (0)

Files changed (2)

 import logging
 import os
 import re
+import unicodedata
 from urllib import urlencode
 from urllib2 import Request, urlopen
 from urlparse import urlparse
 from django.core.urlresolvers import reverse
 from django.http import HttpResponse
 from django.template import loader, RequestContext
+from django.template.defaultfilters import stringfilter
 from django.utils.safestring import mark_safe
 
 import mango
     return wrapper
 scripts = scripts()
 
+def slugify(text):
+    """
+    Normalizes string, converts to lowercase, removes non-alpha characters
+    (except full stops), and converts spaces to hyphens.
+    """
+    text = unicodedata.normalize('NFKD', text).encode('ascii', 'ignore')
+    text = '.'.join([re.sub(r'[^\w\s-]', '', t) for t in text.split('.')]).strip().lower()
+    return mark_safe(unicode(re.sub(r'[-\s]+', '-', text)))
+slugify = stringfilter(slugify)
+
 def stylesheets():
     def _(): pass
     _.cache = None
 from django.core.mail import EmailMultiAlternatives
 from django.core.urlresolvers import reverse
 from django.http import HttpResponseRedirect, HttpResponseServerError
-from django.template.defaultfilters import slugify
 from django.template.loader import render_to_string
 
 from mango.settings import DISQUS, DISQUS_API_KEY, FORUM, SITE_TITLE, SOURCE_SUFFIX, SUBSCRIPTIONS
 if SUBSCRIPTIONS:
     from mango.models import Subscription
 from mango.templatetags.mango_extras import _convert, convert
-from mango.utils import html_response, logger, primary_author_email, replace, text_response
+from mango.utils import (html_response, logger, primary_author_email, replace,
+        slugify, text_response)
 
 @baseurl
 def archives(request):