Skip to content
This repository has been archived by the owner on Oct 29, 2019. It is now read-only.

Commit

Permalink
Merge pull request #272 from czpython/fixes/search-index-2
Browse files Browse the repository at this point in the history
Fixes/search index 2
  • Loading branch information
czpython committed Jul 22, 2015
2 parents 461d547 + d097151 commit cb5c9ba
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
6 changes: 6 additions & 0 deletions aldryn_newsblog/search_indexes.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,9 @@ def get_model(self):

def get_search_data(self, article, language, request):
return article.search_data

def should_update(self, instance, **kwargs):
using = getattr(self, '_backend_alias', DEFAULT_ALIAS)
language = self.get_current_language(using=using, obj=instance)
translations = instance.get_available_languages()
return translations.filter(language_code=language).exists()
16 changes: 16 additions & 0 deletions aldryn_newsblog/tests/test_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,19 @@ def test_translated_article_is_indexed_using_prepare(self):

self.assertEquals(data['language'], 'de')
self.assertEquals(data['url'], article.get_absolute_url('de'))

def test_article_not_indexed_if_no_translation(self):
index = self.get_index()
# create english article
article = self.create_article()

# should the index be updated for this object? (yes)
should_update = index.should_update(article)
self.assertEquals(should_update, True)

# remove all translations for article
article.translations.all().delete()

# should the index be updated for this object? (no)
should_update = index.should_update(article)
self.assertEquals(should_update, False)

0 comments on commit cb5c9ba

Please sign in to comment.