Skip to content

Commit

Permalink
Merge branch 'release/0.6'
Browse files Browse the repository at this point in the history
  • Loading branch information
beniwohli committed Jul 17, 2012
2 parents 78c2405 + 609ebd9 commit 6f661db
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 59 deletions.
2 changes: 1 addition & 1 deletion cms_search/__init__.py
@@ -1 +1 @@
__version__ = '0.5.3'
__version__ = '0.6'
28 changes: 14 additions & 14 deletions cms_search/search_indexes.py
@@ -1,16 +1,13 @@
from django.template import RequestContext
import re

from django.conf import settings
from django.core.exceptions import ImproperlyConfigured
from django.db.models import Q
from django.template import RequestContext
from django.test.client import RequestFactory
from django.utils.encoding import force_unicode
from django.utils.translation import get_language, activate
from django.db.models import Q

try:
from django.test.client import RequestFactory
except ImportError:
from cms_search.utils import RequestFactory

def _strip_tags(value):
"""
Expand Down Expand Up @@ -47,7 +44,7 @@ def _get_index_base():

rf = RequestFactory()

def page_index_factory(language_code, proxy_model):
def page_index_factory(language_code):

class _PageIndex(_get_index_base()):
_language = language_code
Expand All @@ -63,17 +60,19 @@ class _PageIndex(_get_index_base()):
def prepare(self, obj):
current_languge = get_language()
try:
activate(self._language)
if current_languge != self._language:
activate(self._language)
request = rf.get("/")
request.session = {}
request.LANGUAGE_CODE = self._language
self.prepared_data = super(_PageIndex, self).prepare(obj)
plugins = CMSPlugin.objects.filter(language=language_code, placeholder__in=obj.placeholders.all())
text = u''
for plugin in plugins:
instance, _ = plugin.get_plugin_instance()
for base_plugin in plugins:
instance, plugin_type = base_plugin.get_plugin_instance()
if hasattr(instance, 'search_fields'):
text += u' '.join(force_unicode(_strip_tags(getattr(instance, field, ''))) for field in instance.search_fields)
if getattr(instance, 'search_fulltext', False):
if getattr(instance, 'search_fulltext', False) or getattr(plugin_type, 'search_fulltext', False):
text += _strip_tags(instance.render_plugin(context=RequestContext(request))) + u' '
text += obj.get_meta_description() or u''
text += u' '
Expand All @@ -82,7 +81,8 @@ def prepare(self, obj):
self.prepared_data['language'] = self._language
return self.prepared_data
finally:
activate(current_languge)
if get_language() != current_languge:
activate(current_languge)

def index_queryset(self):
# get the correct language and exclude pages that have a redirect
Expand All @@ -98,8 +98,8 @@ def index_queryset(self):

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)
index = page_index_factory(language_code)
if proxy_model:
site.register(proxy_model, index)
else:
print "no page proxy model found for language %s" % language_code
print "no page proxy model found for language %s" % language_code
40 changes: 0 additions & 40 deletions cms_search/utils.py

This file was deleted.

4 changes: 2 additions & 2 deletions docs/conf.py
Expand Up @@ -46,9 +46,9 @@
# built documents.
#
# The short X.Y version.
version = '0.5.3'
version = '0.6'
# The full version, including alpha/beta/rc tags.
release = '0.5.3'
release = '0.6'

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down
21 changes: 19 additions & 2 deletions docs/index.rst
Expand Up @@ -5,6 +5,14 @@ django-cms-search
This package provides multilingual search indexes for easy Haystack integration
with `django CMS <http://www.django-cms.org>`_.

Requirements
============

* Django >= 1.3
* django CMS >= 2.1.3
* django-haystack >= 1.2.4, < 2.0 (support for 2.0 will be a priority once it is released)
* django-classy-tags >= 0.3.2

Usage
=====

Expand All @@ -21,13 +29,13 @@ After installing django-cms-search through your package manager of choice, add
apphook_pool.register(HaystackSearchApphook)

For setting up Haystack, please refer to their
`documentation <http://readthedocs.org/docs/django-haystack/en/latest/>`_.
`documentation <http://django-haystack.readthedocs.org/en/v1.2.7/>`_.

Customizing the Index
---------------------

You can customize what parts of a :class:`~cms.models.CMSPlugin` end up in
the index with two class attributes on :class:`~cms.models.CMSPlugin`
the index with two class attributes on :class:`~cms.plugin_base.CMSPluginBase`
subclasses:

.. attribute:: search_fields
Expand All @@ -39,6 +47,15 @@ subclasses:
if ``True``, the index renders the plugin and adds the result (sans HTML
tags) to the index.

.. note::

Before version 0.6 of this library, this attributes had to be defined on
:class:`~cms.models.CMSPlugin`. Starting with 0.6, it can also be defined
on :class:`~cms.plugin_base.CMSPluginBase`, for cases where one
:class:`~cms.models.CMSPlugin` subclass is used by multiple
:class:`~cms.plugin_base.CMSPluginBase` subclasses with different search
requirements.

Helpers
=======

Expand Down
1 change: 1 addition & 0 deletions setup.py
Expand Up @@ -4,6 +4,7 @@

install_requires = [
'setuptools',
'Django>=1.3',
'django-cms>=2.1.3',
'django-classy-tags>=0.3.2',
'django-haystack>=1.2.4',
Expand Down

0 comments on commit 6f661db

Please sign in to comment.