|
|
@ -1,15 +1,15 @@ |
|
|
|
# -*- coding: utf-8 -*- |
|
|
|
# -*- coding: utf-8 -*- |
|
|
|
from __future__ import unicode_literals |
|
|
|
from __future__ import unicode_literals |
|
|
|
# Erik Stein <code@classlibrary.net>, 2015 |
|
|
|
# Erik Stein <code@classlibrary.net>, 2015-2017 |
|
|
|
|
|
|
|
|
|
|
|
from django.utils.text import slugify |
|
|
|
from django.utils.text import slugify |
|
|
|
from django.utils import six |
|
|
|
from django.utils import six |
|
|
|
from django.utils.encoding import force_text |
|
|
|
from django.utils.encoding import force_text, smart_text |
|
|
|
from django.utils.functional import allow_lazy |
|
|
|
from django.utils.functional import allow_lazy |
|
|
|
from django.utils.safestring import SafeText |
|
|
|
from django.utils.safestring import SafeText |
|
|
|
|
|
|
|
|
|
|
|
# import unicodedata |
|
|
|
from BeautifulSoup import BeautifulStoneSoup |
|
|
|
import translitcodec |
|
|
|
import translitcodec # provides 'translit/long', used by codecs.encode() |
|
|
|
import codecs |
|
|
|
import codecs |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -27,21 +27,11 @@ def slugify_long(value): |
|
|
|
slugify_long = allow_lazy(slugify_long, six.text_type, SafeText) |
|
|
|
slugify_long = allow_lazy(slugify_long, six.text_type, SafeText) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def slugify_german(value): |
|
|
|
# Spreading umlauts is included in the translit/long codec. |
|
|
|
""" |
|
|
|
slugify_german = slugify_long |
|
|
|
Transliterates Umlaute before calling django's slugify function. |
|
|
|
|
|
|
|
""" |
|
|
|
|
|
|
|
umlaute = { |
|
|
|
|
|
|
|
'Ä': 'Ae', |
|
|
|
|
|
|
|
'Ö': 'Oe', |
|
|
|
|
|
|
|
'Ü': 'Ue', |
|
|
|
|
|
|
|
'ä': 'ae', |
|
|
|
|
|
|
|
'ö': 'oe', |
|
|
|
|
|
|
|
'ü': 'ue', |
|
|
|
|
|
|
|
'ß': 'ss', |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
value = force_text(value) |
|
|
|
|
|
|
|
umap = {ord(key): unicode(val) for key, val in umlaute.items()} |
|
|
|
def html_entities_to_unicode(html): |
|
|
|
return slugify(value.translate(umap)) |
|
|
|
text = smart_text(BeautifulStoneSoup(html, convertEntities=BeautifulStoneSoup.ALL_ENTITIES)) |
|
|
|
slugify_german = allow_lazy(slugify_german, six.text_type, SafeText) |
|
|
|
return text |
|
|
|
|
|
|
|
html_entities_to_unicode = allow_lazy(html_entities_to_unicode, six.text_type, SafeText) |
|
|
|