Set the correct language during indexing

This commit is contained in:
Iacopo Spalletti 2016-07-13 01:12:25 +02:00
parent 7c4b3a7c76
commit beb058f27e
No known key found for this signature in database
GPG key ID: BDCBC2EB289F60C6

View file

@ -3,6 +3,7 @@ from aldryn_search.helpers import get_plugin_index_data
from aldryn_search.utils import get_index_base, strip_tags from aldryn_search.utils import get_index_base, strip_tags
from django.utils.encoding import force_text from django.utils.encoding import force_text
from haystack import indexes from haystack import indexes
from parler.utils.context import switch_language
from .models import Post from .models import Post
from .settings import get_setting from .settings import get_setting
@ -44,6 +45,7 @@ class PostIndex(get_index_base()):
return Post return Post
def get_search_data(self, post, language, request): def get_search_data(self, post, language, request):
with switch_language(post, language):
description = post.get_description() description = post.get_description()
abstract = strip_tags(post.safe_translation_getter('abstract', default='')) abstract = strip_tags(post.safe_translation_getter('abstract', default=''))
keywords = post.get_keywords() keywords = post.get_keywords()