From c94b328dd74ec37ec9139e48fd6457aa65632008 Mon Sep 17 00:00:00 2001 From: Erik Stein Date: Thu, 2 Nov 2017 09:30:37 +0100 Subject: [PATCH] Fixed html_entities_to_unicode (works only in Python 3). --- shared/utils/text.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/shared/utils/text.py b/shared/utils/text.py index d341ff0..5e1ecff 100644 --- a/shared/utils/text.py +++ b/shared/utils/text.py @@ -2,6 +2,8 @@ from __future__ import unicode_literals # Erik Stein , 2015-2017 +import html + from django.utils import six from django.utils.encoding import force_text, smart_text from django.utils.functional import allow_lazy, keep_lazy_text @@ -32,15 +34,21 @@ slugify_long = allow_lazy(slugify_long, six.text_type, SafeText) slugify_german = slugify_long -def html_entities_to_unicode(html): - text = smart_text(BeautifulStoneSoup(html, convertEntities=BeautifulStoneSoup.ALL_ENTITIES)) - return text +# Does not work anymore with bs4 +# def html_entities_to_unicode(html): +# text = smart_text(BeautifulStoneSoup(html, convertEntities=BeautifulStoneSoup.ALL_ENTITIES)) +# return text + +# Works only with Python >= 3.4 +def html_entities_to_unicode(html_str): + return html.unescape(html_str) html_entities_to_unicode = allow_lazy(html_entities_to_unicode, six.text_type, SafeText) # Translators: This string is used as a separator between list elements DEFAULT_SEPARATOR = ugettext_lazy(", ") + @keep_lazy_text def get_text_joined(list_, separator=DEFAULT_SEPARATOR, last_word=ugettext_lazy(' and ')): list_ = list(list_)