2 from fnpdjango.utils.text import char_map
5 # Specifies diacritics order.
6 # Default order is zero, max is 9
15 order = char_order.get(char, 0)
16 return "%s~%d" % (char_map[char], order)
23 Turns Unicode into ASCII-sortable str
27 >>> sortify('a a') < sortify('aa') < sortify('ą') < sortify('b')
30 >>> sortify('ź') < sortify('ż')
35 if not isinstance(value, str):
36 value = str(value, 'utf-8')
38 # try to replace chars
39 value = re.sub('[^a-zA-Z0-9\\s\\-]', replace_char, value)
41 value = re.sub(r'[^a-z0-9~]+', ' ', value)
43 return value.encode('ascii', 'ignore').decode('ascii')