Add tools - unaccent

This commit is contained in:
resteve 2016-04-12 15:36:26 +02:00
parent 2b3ff56196
commit e6a2cbc3d9
1 changed files with 21 additions and 0 deletions

21
tools.py Normal file
View File

@ -0,0 +1,21 @@
# encoding: utf-8
# This file is part account_payment_gateway module for Tryton.
# The COPYRIGHT file at the top level of this repository contains
# the full copyright notices and license terms.
import unicodedata
SRC_CHARS = u"""/*+?¿!&$[]{}@#`^<>=~%|\\"""
def unaccent(text):
if not (isinstance(text, str) or isinstance(text, unicode)):
return str(text)
if isinstance(text, str):
text = unicode(text, 'utf-8')
text = text.lower()
for c in xrange(len(SRC_CHARS)):
text = text.replace(SRC_CHARS[c], '')
text = text.replace(u'º', '. ')
text = text.replace(u'ª', '. ')
text = text.replace(u' ', ' ')
return unicodedata.normalize('NFKD', text).encode('ASCII', 'ignore')