Migrating to apphook config
This commit is contained in:
parent
df7405a3b4
commit
989a91c6ee
2 changed files with 7 additions and 11 deletions
|
@ -1,16 +1,12 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
from aldryn_search.helpers import get_plugin_index_data
|
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 haystack import indexes
|
from haystack import indexes
|
||||||
|
|
||||||
from .models import Post
|
from .models import Post
|
||||||
from .settings import get_setting
|
from .settings import get_setting
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
|
|
||||||
class PostIndex(get_index_base()):
|
class PostIndex(get_index_base()):
|
||||||
haystack_use_for_indexing = get_setting('ENABLE_SEARCH')
|
haystack_use_for_indexing = get_setting('ENABLE_SEARCH')
|
||||||
|
@ -61,16 +57,16 @@ class PostIndex(get_index_base()):
|
||||||
# text_bits.append(' '.join(post.get_keywords()))
|
# text_bits.append(' '.join(post.get_keywords()))
|
||||||
for category in post.categories.all():
|
for category in post.categories.all():
|
||||||
text_bits.append(
|
text_bits.append(
|
||||||
force_unicode_or_text(category.safe_translation_getter('name')))
|
force_text(category.safe_translation_getter('name')))
|
||||||
for tag in post.tags.all():
|
for tag in post.tags.all():
|
||||||
text_bits.append(force_unicode_or_text(tag.name))
|
text_bits.append(force_text(tag.name))
|
||||||
if post.content:
|
if post.content:
|
||||||
plugins = post.content.cmsplugin_set.filter(language=language)
|
plugins = post.content.cmsplugin_set.filter(language=language)
|
||||||
for base_plugin in plugins:
|
for base_plugin in plugins:
|
||||||
content = get_plugin_index_data(base_plugin, request)
|
content = get_plugin_index_data(base_plugin, request)
|
||||||
text_bits.append(content)
|
text_bits.append(content)
|
||||||
for attribute in optional_attributes:
|
for attribute in optional_attributes:
|
||||||
value = force_unicode_or_text(getattr(post, attribute))
|
value = force_text(getattr(post, attribute))
|
||||||
if value and value not in text_bits:
|
if value and value not in text_bits:
|
||||||
text_bits.append(value)
|
text_bits.append(value)
|
||||||
return ' '.join(text_bits)
|
return ' '.join(text_bits)
|
||||||
|
|
|
@ -4,7 +4,7 @@ from __future__ import absolute_import, print_function, unicode_literals
|
||||||
from haystack.constants import DEFAULT_ALIAS
|
from haystack.constants import DEFAULT_ALIAS
|
||||||
from haystack.query import SearchQuerySet
|
from haystack.query import SearchQuerySet
|
||||||
|
|
||||||
from djangocms_blog.search_indexes import PostIndex
|
from djangocms_blog.models import Post
|
||||||
|
|
||||||
from .base import BaseTest
|
from .base import BaseTest
|
||||||
|
|
||||||
|
@ -12,7 +12,7 @@ from .base import BaseTest
|
||||||
class BlogIndexingTests(BaseTest):
|
class BlogIndexingTests(BaseTest):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.index = PostIndex()
|
self.get_pages()
|
||||||
|
|
||||||
def test_blog_post_is_indexed_using_prepare(self):
|
def test_blog_post_is_indexed_using_prepare(self):
|
||||||
"""This tests the indexing path way used by update_index mgmt command"""
|
"""This tests the indexing path way used by update_index mgmt command"""
|
||||||
|
@ -44,5 +44,5 @@ class BlogIndexingTests(BaseTest):
|
||||||
|
|
||||||
def test_searchqueryset(self):
|
def test_searchqueryset(self):
|
||||||
posts = self.get_posts()
|
posts = self.get_posts()
|
||||||
all_results = SearchQuerySet().all()
|
all_results = SearchQuerySet().models(Post)
|
||||||
self.assertEqual(len(posts), len(all_results))
|
self.assertEqual(len(posts), len(all_results))
|
||||||
|
|
Loading…
Reference in a new issue