Created
August 11, 2011 22:57
-
-
Save fmobus/1141017 to your computer and use it in GitHub Desktop.
remoção de acentos (depende de django)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# disclaimer | |
# essa implementação é um tanto presa a funções da biblioteca do django | |
# basicamente por pura preguiça/conveniência minha | |
# | |
from django.utils.encoding import smart_str, force_unicode | |
import unicodedata | |
def remove_accents(value): | |
if not isinstance(value,unicode): | |
try: | |
value = force_unicode(value); | |
except UnicodeDecodeError, e: | |
print smart_str(value); | |
print "UnicodeDecodeError", value; | |
pass | |
nkfd_form = unicodedata.normalize('NFKD', value); | |
only_ascii = nkfd_form.encode('ASCII', 'ignore') | |
return only_ascii |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment