|
|
@ -2,11 +2,12 @@ |
|
|
|
from __future__ import unicode_literals |
|
|
|
from __future__ import unicode_literals |
|
|
|
# Erik Stein <code@classlibrary.net>, 2015-2017 |
|
|
|
# Erik Stein <code@classlibrary.net>, 2015-2017 |
|
|
|
|
|
|
|
|
|
|
|
from django.utils.text import slugify |
|
|
|
|
|
|
|
from django.utils import six |
|
|
|
from django.utils import six |
|
|
|
from django.utils.encoding import force_text, smart_text |
|
|
|
from django.utils.encoding import force_text, smart_text |
|
|
|
from django.utils.functional import allow_lazy |
|
|
|
from django.utils.functional import allow_lazy, keep_lazy_text |
|
|
|
from django.utils.safestring import SafeText |
|
|
|
from django.utils.safestring import SafeText |
|
|
|
|
|
|
|
from django.utils.text import slugify |
|
|
|
|
|
|
|
from django.utils.translation import ugettext as _, ugettext_lazy |
|
|
|
|
|
|
|
|
|
|
|
from bs4 import BeautifulStoneSoup |
|
|
|
from bs4 import BeautifulStoneSoup |
|
|
|
import translitcodec # provides 'translit/long', used by codecs.encode() |
|
|
|
import translitcodec # provides 'translit/long', used by codecs.encode() |
|
|
@ -35,3 +36,18 @@ def html_entities_to_unicode(html): |
|
|
|
text = smart_text(BeautifulStoneSoup(html, convertEntities=BeautifulStoneSoup.ALL_ENTITIES)) |
|
|
|
text = smart_text(BeautifulStoneSoup(html, convertEntities=BeautifulStoneSoup.ALL_ENTITIES)) |
|
|
|
return text |
|
|
|
return text |
|
|
|
html_entities_to_unicode = allow_lazy(html_entities_to_unicode, six.text_type, SafeText) |
|
|
|
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_) |
|
|
|
|
|
|
|
if len(list_) == 0: |
|
|
|
|
|
|
|
return '' |
|
|
|
|
|
|
|
if len(list_) == 1: |
|
|
|
|
|
|
|
return force_text(list_[0]) |
|
|
|
|
|
|
|
return '%s%s%s' % ( |
|
|
|
|
|
|
|
separator.join(force_text(i) for i in list_[:-1]), |
|
|
|
|
|
|
|
force_text(last_word), force_text(list_[-1])) |
|
|
|