Haystack/Django-CMS integration

Python

New/Simple BSD

Creates a search index for django-cms pages

Download (right click, save as, rename as appropriate)

Embed

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
import datetime
from cms.models import Page     
from haystack.indexes import *
from haystack import site


class PageIndex(SearchIndex):
    text = CharField(document=True, use_template=True, model_attr='text')
    title = CharField(model_attr='get_page_title')
    get_slug = CharField(model_attr='get_slug')

    def prepare_text(self,obj):
        renderedplugins = ""
        for i in obj.cmsplugin_set.all():
            renderedplugins += i.render_plugin(context={})
        return renderedplugins

    def get_queryset(self):
        return Page.objects.filter(publication_date__lte=datetime.datetime.now(), published=True)

site.register(Page, PageIndex)