dot is not valid in family name

This commit is contained in:
Emmanuel Garette 2019-12-22 08:37:30 +01:00
parent 881b551f47
commit f062d9f30a
1 changed files with 8 additions and 12 deletions

View File

@ -2,25 +2,21 @@
utilitaires créole
"""
import unicodedata
from .i18n import _
# définition des classes d'adresse IP existantes
def normalize_family(family_name, check_name=True):
"""
il ne faut pas d'espace, d'accent, de majuscule, de tiré, ...
dans le nom des familles
def normalize_family(family_name: str,
check_name=True) -> str:
"""replace space, accent, uppercase, ... by valid character
"""
f = family_name
f = f.replace('-', '_')
#f = f.replace(u'é', 'e')
#f = f.replace(u'è', 'e')
nfkd_form = unicodedata.normalize('NFKD', f)
f = u"".join([c for c in nfkd_form if not unicodedata.combining(c)])
f = f.replace('.', '_')
f = f.replace(' ', '_')
nfkd_form = unicodedata.normalize('NFKD', f)
f = ''.join([c for c in nfkd_form if not unicodedata.combining(c)])
f = f.lower()
if f[0].isnumeric():
raise ValueError(u'Le nom de la famille ne doit pas commencer par un chiffre : {0}'.format(f))
if check_name and f == 'containers':
raise ValueError(u'nom de la famille interdit {0}'.format(f))
raise ValueError(_('"{0}" is a forbidden family name'.format(f)))
return f