Skip to content

Commit

Permalink
Fix PY3 unicode error
Browse files Browse the repository at this point in the history
  • Loading branch information
Marco Federighi committed Oct 20, 2015
1 parent 0f45339 commit ea8123d
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions 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

Expand Down Expand Up @@ -60,16 +63,16 @@ def get_search_data(self, post, language, request):
#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)
Expand Down

0 comments on commit ea8123d

Please sign in to comment.