Permalink
Browse files

Merge branch 'release/0.6'

  • Loading branch information...
2 parents 78c2405 + 609ebd9 commit 6f661db8ec73928d0ba98777b3ec52652ed42b72 @piquadrat committed Jul 17, 2012
Showing with 37 additions and 59 deletions.
  1. +1 −1 cms_search/__init__.py
  2. +14 −14 cms_search/search_indexes.py
  3. +0 −40 cms_search/utils.py
  4. +2 −2 docs/conf.py
  5. +19 −2 docs/index.rst
  6. +1 −0 setup.py
View
@@ -1 +1 @@
-__version__ = '0.5.3'
+__version__ = '0.6'
@@ -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):
"""
@@ -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
@@ -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' '
@@ -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
@@ -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
View
@@ -1,40 +0,0 @@
-from django.test import Client
-from django.core.handlers.wsgi import WSGIRequest
-
-class RequestFactory(Client):
- """
- From: http://djangosnippets.org/snippets/963/
-
- Class that lets you create mock Request objects for use in testing.
-
- Usage:
-
- rf = RequestFactory()
- get_request = rf.get('/hello/')
- post_request = rf.post('/submit/', {'foo': 'bar'})
-
- This class re-uses the django.test.client.Client interface, docs here:
- http://www.djangoproject.com/documentation/testing/#the-test-client
-
- Once you have a request object you can pass it to any view function,
- just as if that view had been hooked up using a URLconf.
-
- """
- def request(self, **request):
- """
- Similar to parent class, but returns the request object as soon as it
- has created it.
- """
- environ = {
- 'HTTP_COOKIE': self.cookies,
- 'PATH_INFO': '/',
- 'QUERY_STRING': '',
- 'REQUEST_METHOD': 'GET',
- 'SCRIPT_NAME': '',
- 'SERVER_NAME': 'testserver',
- 'SERVER_PORT': 80,
- 'SERVER_PROTOCOL': 'HTTP/1.1',
- }
- environ.update(self.defaults)
- environ.update(request)
- return WSGIRequest(environ)
View
@@ -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.
View
@@ -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
=====
@@ -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
@@ -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
=======
View
@@ -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',

0 comments on commit 6f661db

Please sign in to comment.