les noms des machines sont maintenant ultra cleans
This commit is contained in:
parent
716124e9d5
commit
0fce45a997
@ -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)
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user