2019-11-23 08:17:35 +01:00
|
|
|
"""
|
|
|
|
utilitaires créole
|
|
|
|
"""
|
2019-11-26 20:33:24 +01:00
|
|
|
import unicodedata
|
2019-12-22 08:37:30 +01:00
|
|
|
from .i18n import _
|
2019-11-23 08:17:35 +01:00
|
|
|
|
|
|
|
|
2019-12-22 08:37:30 +01:00
|
|
|
def normalize_family(family_name: str,
|
2019-12-22 08:45:03 +01:00
|
|
|
check_name: bool=True,
|
|
|
|
allow_dot: bool=False) -> str:
|
2019-12-22 08:37:30 +01:00
|
|
|
"""replace space, accent, uppercase, ... by valid character
|
2019-11-23 08:17:35 +01:00
|
|
|
"""
|
2019-11-26 20:33:24 +01:00
|
|
|
f = family_name
|
2019-11-23 08:17:35 +01:00
|
|
|
f = f.replace('-', '_')
|
2019-12-22 08:45:03 +01:00
|
|
|
if not allow_dot:
|
|
|
|
f = f.replace('.', '_')
|
2019-11-23 08:17:35 +01:00
|
|
|
f = f.replace(' ', '_')
|
2019-12-22 08:37:30 +01:00
|
|
|
nfkd_form = unicodedata.normalize('NFKD', f)
|
|
|
|
f = ''.join([c for c in nfkd_form if not unicodedata.combining(c)])
|
2019-11-23 08:17:35 +01:00
|
|
|
f = f.lower()
|
2019-11-26 20:33:24 +01:00
|
|
|
if check_name and f == 'containers':
|
2019-12-22 08:37:30 +01:00
|
|
|
raise ValueError(_('"{0}" is a forbidden family name'.format(f)))
|
2019-11-23 08:17:35 +01:00
|
|
|
return f
|
|
|
|
|