1
0
mirror of https://gitlab.crans.org/bde/nk20 synced 2024-11-26 18:37:12 +00:00

🎨 Normalize - to _ since these characters are used a lot

This commit is contained in:
Yohann D'ANELLO 2020-08-24 11:54:00 +02:00
parent bac14521ae
commit 550242226e

View File

@ -247,7 +247,8 @@ class Alias(models.Model):
Normalizes a string: removes most diacritics, does casefolding and ignore non-ASCII characters Normalizes a string: removes most diacritics, does casefolding and ignore non-ASCII characters
""" """
return ''.join( return ''.join(
char for char in unicodedata.normalize('NFKD', string.casefold().replace('æ', 'ae').replace('œ', 'oe')) char for char in unicodedata.normalize('NFKD', string.casefold().replace('æ', 'ae')
.replace('œ', 'oe').replace('-', '_'))
if all(not unicodedata.category(char).startswith(cat) if all(not unicodedata.category(char).startswith(cat)
for cat in {'M', 'P', 'Z', 'C'})).casefold().encode('ascii', 'ignore').decode('ascii') for cat in {'M', 'P', 'Z', 'C'})).casefold().encode('ascii', 'ignore').decode('ascii')