X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/6280673f35e13e75e81c5b7821bd2a44a1831eab..357027375ff8867f42ca34bcbfb5a78b5b185fc3:/src/funding/utils.py diff --git a/src/funding/utils.py b/src/funding/utils.py new file mode 100644 index 000000000..c16c9d93d --- /dev/null +++ b/src/funding/utils.py @@ -0,0 +1,26 @@ +# -*- 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 +import string +from fnpdjango.utils.text.slughifi import char_map + +# PayU chokes on non-Polish diacritics. +# Punctuation is handled correctly and escaped as needed, +# with the notable exception of backslash. +sane_in_payu_title = re.escape( + string.uppercase + + string.lowercase + + u'ąćęłńóśźżĄĆĘŁŃÓŚŹŻ' + + string.digits + + ' ' + + "".join(set(string.punctuation) - set('\\')) +) + +def replace_char(m): + char = m.group() + return char_map.get(char, '') + +def sanitize_payment_title(value): + return re.sub('[^%s]{1}' % sane_in_payu_title, replace_char, unicode(value))