les noms des machines sont maintenant ultra cleans

This commit is contained in:
Romain Beuque 2015-03-25 14:01:17 +01:00
parent 716124e9d5
commit 0fce45a997
2 changed files with 82 additions and 70 deletions

View File

@ -441,7 +441,9 @@ class MachineAddController(AuthenticatedRestController):
mac = mac.strip()
name = name.strip().replace(" ", "-").replace("_", "-")
name = Translations.strip_accents(name)
name = Translations.formatName(name)
#name = Translations.strip_accents(name)
#Vérification que l'adresse mac soit correcte
mac_match = re.match('^([0-9A-Fa-f]{2}[:-]?){5}([0-9A-Fa-f]{2})$', mac)

View File

@ -33,16 +33,26 @@ class Translations(object):
#end if
#end def
#end class
# http://stackoverflow.com/questions/517923/what-is-the-best-way-to-remove-accents-in-a-python-unicode-string
@staticmethod
def strip_accents(s):
return ''.join((c for c in unicodedata.normalize('NFD', s) if unicodedata.category(c) != 'Mn'))
#end def
@staticmethod
def formatName(value):
"""
Converts to ASCII. Converts spaces to hyphens. Removes characters that
aren't alphanumerics, underscores, or hyphens. Converts to lowercase.
Also strips leading and trailing whitespace.
"""
value = unicodedata.normalize('NFKD', value).encode('ascii', 'ignore').decode('ascii')
value = re.sub('[^\w\s-]', '', value).strip().lower()
return re.sub('[-\s]+', '-', value)
#end def
#end class
class Passwords(object):
@staticmethod