Make sure all device state categories are slugified

pull/2/head
Paulus Schoutsen 2013-12-07 12:54:19 -08:00
parent 08f4c70b4e
commit 8124188264
2 changed files with 13 additions and 5 deletions

View File

@ -278,10 +278,8 @@ class DeviceTracker(object):
# Make sure that each device is mapped
# to a unique category name
name = row['name']
if not name:
name = "unnamed_device"
name = util.slugify(row['name']) if row['name'] \
else "unnamed_device"
tries = 0
suffix = ""

View File

@ -2,7 +2,17 @@
import re
RE_SANITIZE_FILENAME = re.compile(r"(~|(\.\.)|/|\+)")
RE_SLUGIFY = re.compile(r'[^A-Za-z0-9_]+')
def sanitize_filename(filename):
""" Sanitizes a filename by removing .. / and \\. """
return re.sub(r"(~|(\.\.)|/|\+)", "", filename)
return RE_SANITIZE_FILENAME.sub("", filename)
def slugify(text):
""" Slugifies a given text. """
text = text.strip().replace(" ", "_")
return RE_SLUGIFY.sub("", text)