Skip to content

Made haystack-2.0.0beta compatible #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@
django-cms-search
=================

fork notes:
=================
This package has been modified to work with current django-haystack 2.0.0-beta in a pretty clean way.





This package provides multilingual search indexes for easy Haystack integration with django CMS.

Usage
Expand Down
38 changes: 18 additions & 20 deletions cms_search/search_indexes.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,29 +26,18 @@ def _strip_tags(value):
except ImportError:
from django.utils import importlib

from haystack import indexes, site
from haystack import indexes, connections

from cms.models.pluginmodel import CMSPlugin

from cms_search import models as proxy_models
from cms_search import settings as search_settings

def _get_index_base():
index_string = search_settings.INDEX_BASE_CLASS
module, class_name = index_string.rsplit('.', 1)
mod = importlib.import_module(module)
base_class = getattr(mod, class_name, None)
if not base_class:
raise ImproperlyConfigured('CMS_SEARCH_INDEX_BASE_CLASS: module %s has no class %s' % (module, class_name))
if not issubclass(base_class, indexes.SearchIndex):
raise ImproperlyConfigured('CMS_SEARCH_INDEX_BASE_CLASS: %s is not a subclass of haystack.indexes.SearchIndex' % search_settings.INDEX_BASE_CLASS)
return base_class

rf = RequestFactory()

def page_index_factory(language_code, proxy_model):

class _PageIndex(_get_index_base()):
class _PageIndex(indexes.SearchIndex, indexes.Indexable):
language = language_code

text = indexes.CharField(document=True, use_template=False)
Expand Down Expand Up @@ -78,6 +67,9 @@ def prepare(self, obj):
finally:
activate(current_languge)

def get_model(self):
return proxy_model

def index_queryset(self):
qs = proxy_model.objects.published().filter(title_set__language=language_code).distinct()
if 'publisher' in settings.INSTALLED_APPS:
Expand All @@ -86,10 +78,16 @@ def index_queryset(self):

return _PageIndex

for language_code, language_name in settings.LANGUAGES:
proxy_model = getattr(proxy_models, proxy_models.proxy_name(language_code))
index = page_index_factory(language_code, proxy_model)
if proxy_model:
site.register(proxy_model, index)
else:
print "no page proxy model found for language %s" % language_code

# we don't want the globals() style which was used in models.py ...
def push_indices():
magic_indices = []
for language_code, language_name in settings.LANGUAGES:
proxy_model = getattr(proxy_models, proxy_models.proxy_name(language_code))
magic_indices.append( page_index_factory(language_code, proxy_model))

unified_index = connections['default'].get_unified_index()
prev_indices = [index for key, index in unified_index.indexes.iteritems()]
all_indices = [ind() for ind in magic_indices] + prev_indices
unified_index.build(indexes=all_indices)
push_indices()