1 # This file is part of Wolne Lektury, licensed under GNU Affero GPLv3 or later.
2 # Copyright © Fundacja Wolne Lektury. See NOTICE for more information.
5 from fnpdjango.utils.text import char_map
8 # Specifies diacritics order.
9 # Default order is zero, max is 9
18 order = char_order.get(char, 0)
19 return "%s~%d" % (char_map[char], order)
26 Turns Unicode into ASCII-sortable str
30 >>> sortify('a a') < sortify('aa') < sortify('ą') < sortify('b')
33 >>> sortify('ź') < sortify('ż')
38 if not isinstance(value, str):
39 value = str(value, 'utf-8')
41 # try to replace chars
42 value = re.sub('[^a-zA-Z0-9\\s\\-]', replace_char, value)
44 value = re.sub(r'[^a-z0-9~]+', ' ', value)
46 return value.encode('ascii', 'ignore').decode('ascii')