X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/ae60b2a3949e96357477cc04f90fd0873cee8a92..ecd1f5bc214a8ba61b65d4d00a7e7d09a8c8fa3a:/src/sortify.py?ds=inline diff --git a/src/sortify.py b/src/sortify.py index f1e8bcb8b..027860186 100644 --- a/src/sortify.py +++ b/src/sortify.py @@ -1,12 +1,14 @@ -# -*- coding: utf-8 -*- +# This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later. +# Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information. +# import re -from fnpdjango.utils.text.slughifi import char_map +from fnpdjango.utils.text import char_map # Specifies diacritics order. # Default order is zero, max is 9 char_order = { - u'ż': 1, u'Ż': 1, + 'ż': 1, 'Ż': 1, } @@ -33,12 +35,12 @@ def sortify(value): """ - if not isinstance(value, unicode): - value = unicode(value, 'utf-8') + if not isinstance(value, str): + value = str(value, 'utf-8') # try to replace chars value = re.sub('[^a-zA-Z0-9\\s\\-]', replace_char, value) value = value.lower() value = re.sub(r'[^a-z0-9~]+', ' ', value) - return value.encode('ascii', 'ignore') + return value.encode('ascii', 'ignore').decode('ascii')