Skip to content
Browse files

Merge branch 'release/0.4.1'

  • Loading branch information...
2 parents 3703c9d + 78720d5 commit dcd8d2070d2862116dbe1701ffe914817e44ab8a @piquadrat committed Aug 23, 2011
Showing with 54 additions and 4 deletions.
  1. +1 −1 cms_search/__init__.py
  2. +11 −1 cms_search/search_indexes.py
  3. +40 −0 cms_search/utils.py
  4. +2 −2 docs/conf.py
View
2 cms_search/__init__.py
@@ -1 +1 @@
-__version__ = '0.4'
+__version__ = '0.4.1'
View
12 cms_search/search_indexes.py
@@ -1,10 +1,16 @@
+from django.template import RequestContext
import re
from django.conf import settings
from django.core.exceptions import ImproperlyConfigured
from django.utils.encoding import force_unicode
from django.utils.translation import get_language, activate
+try:
+ from django.test.client import RequestFactoryII
+except ImportError:
+ from cms_search.utils import RequestFactory
+
def _strip_tags(value):
"""
Returns the given HTML with all tags stripped.
@@ -38,6 +44,8 @@ def _get_index_base():
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()):
@@ -54,6 +62,8 @@ def prepare(self, obj):
current_languge = get_language()
try:
activate(self.language)
+ request = rf.get("/")
+ request.session = {}
self.prepared_data = super(_PageIndex, self).prepare(obj)
plugins = CMSPlugin.objects.filter(language=language_code, placeholder__in=obj.placeholders.all())
text = ''
@@ -62,7 +72,7 @@ def prepare(self, obj):
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):
- text += _strip_tags(instance.render_plugin())
+ text += _strip_tags(instance.render_plugin(context=RequestContext(request)))
self.prepared_data['text'] = text
return self.prepared_data
finally:
View
40 cms_search/utils.py
@@ -0,0 +1,40 @@
+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
4 docs/conf.py
@@ -46,9 +46,9 @@
# built documents.
#
# The short X.Y version.
-version = '0.4'
+version = '0.4.1'
# The full version, including alpha/beta/rc tags.
-release = '0.4'
+release = '0.4.1'
# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.

0 comments on commit dcd8d20

Please sign in to comment.
Something went wrong with that request. Please try again.