From 4424b3b971ddc0a60cb32b4752626d5d9f7f1a7f Mon Sep 17 00:00:00 2001 From: Marco Federighi Date: Tue, 20 Oct 2015 18:03:46 +0200 Subject: [PATCH] Fix PY3 unicode error --- djangocms_blog/search_indexes.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/djangocms_blog/search_indexes.py b/djangocms_blog/search_indexes.py index 84afefb..8da597a 100644 --- a/djangocms_blog/search_indexes.py +++ b/djangocms_blog/search_indexes.py @@ -1,6 +1,9 @@ # -*- coding: utf-8 -*- from django.utils.encoding import force_text -from django.utils.text import force_unicode +try: + from django.utils.encoding import force_text as force_unicode_or_text +except ImportError: + from django.utils.encoding import force_unicode as force_unicode_or_text from aldryn_search.helpers import get_plugin_index_data from aldryn_search.utils import get_index_base, strip_tags @@ -60,16 +63,16 @@ class PostIndex(get_index_base()): #text_bits.append(' '.join(post.get_keywords())) for category in post.categories.all(): text_bits.append( - force_text(category.safe_translation_getter('name'))) + force_unicode_or_text(category.safe_translation_getter('name'))) for tag in post.tags.all(): - text_bits.append(force_text(tag.name)) + text_bits.append(force_unicode_or_text(tag.name)) if post.content: plugins = post.content.cmsplugin_set.filter(language=language) for base_plugin in plugins: content = get_plugin_index_data(base_plugin, request) text_bits.append(content) for attribute in optional_attributes: - value = force_unicode(getattr(post, attribute)) + value = force_unicode_or_text(getattr(post, attribute)) if value and value not in text_bits: text_bits.append(value) return ' '.join(text_bits)