Skip to content

Commit

Permalink
Updated the slugify method to handle more invalid characters, be easi…
Browse files Browse the repository at this point in the history
…er to extend, and to produce more appealing output.
  • Loading branch information
lethain committed Jun 4, 2008
1 parent 79ca5e9 commit 2d20676
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions editor/views.py
Expand Up @@ -28,11 +28,22 @@
from django.contrib.auth import views, authenticate



CHARACTERS_TO_STRIP = """ .,!?'";:/\+=# """
def slugify(str):
# This could be substantially more robust,
# but for the moment it suffices.
return str.lower().replace(' ','-').replace('.','').replace(',','-').replace("'","").replace('"',"")[:95]
new_str = ""
replaced_previous = False
for char in str.lower():
if char in CHARACTERS_TO_STRIP:
if replaced_previous:
pass
else:
new_str = new_str + "-"
replaced_previous = True
else:
replaced_previous = False
new_str = new_str + char
return new_str.strip("-")


def login(request):
error_msg = u""
Expand Down

0 comments on commit 2d20676

Please sign in to comment.