Allow unicode values in slugs

Otherwise non-ascii characters get stripped which is not good for
e.g. titles in cyrillic script.
This commit is contained in:
Ivan Habunek 2020-06-10 10:54:28 +02:00
parent 15ca684286
commit 2171a9e08e
No known key found for this signature in database
GPG Key ID: CDBD63C43A30BB95

View File

@ -58,6 +58,6 @@ def slugify(value):
re_pattern = re.compile(r'[^\w\s-]', flags=re.U) re_pattern = re.compile(r'[^\w\s-]', flags=re.U)
re_spaces = re.compile(r'[-\s]+', flags=re.U) re_spaces = re.compile(r'[-\s]+', flags=re.U)
value = str(value) value = str(value)
value = unicodedata.normalize('NFKD', value).encode('ascii', 'ignore').decode('ascii') value = unicodedata.normalize('NFKC', value)
value = re_pattern.sub('', value).strip().lower() value = re_pattern.sub('', value).strip().lower()
return re_spaces.sub('-', value) return re_spaces.sub('_', value)