Hi All,
I'm wondering if anyone would find it useful to allow the slugify
function to take an optional argument that would let us specify what
type of separator to use. Sometimes it might be nice to let slugify
use an underscore instead of a dash. I see that slugify is grouped
with the template filters code so perhaps it's intent is only to be
used as a template tag, but I've seen people using it in raw python
code.
SUGGESTED PSUDOCODE
200 def slugify(value, slug_separator='-'):
....
208 return mark_safe(re.sub('[-\s]+', slug_separator, value))
....
ORIGINAL CODE
http://code.djangoproject.com/browser/django/trunk/django/template/defaultfilters.py
200 def slugify(value):
201 """
202 Normalizes string, converts to lowercase, removes non-alpha
characters,
203 and converts spaces to hyphens.
204 """
205 import unicodedata
206 value = unicodedata.normalize('NFKD', value).encode('ascii',
'ignore')
207 value = unicode(re.sub('[^\w\s-]', '', value).strip().lower())
208 return mark_safe(re.sub('[-\s]+', '-', value))
209 slugify.is_safe = True
210 slugify = stringfilter(slugify)
This is my first post on Django Developers, so I figure I'd introduce
myself. My name is Joe and I'm a Django web developer in Chicago.
I've been working with Django for a few years and find it a lot of
fun!
If this is the wrong place to ask, my apologies. Thanks for reading,
Joe