django-cms-search Documentation

Similar documents
django-subdomains Documentation

django-sekizai Documentation

MIT AITI Python Software Development Lab DJ1:

Django-Select2 Documentation. Nirupam Biswas

LFC - Lightning Fast CMS Documentation

django-avatar Documentation

django-intercom Documentation

Django Admin Sortable Documentation

django-scaffold Documentation

wagtailmenus Documentation

cmsplugin-blog Release post 0 Øyvind Saltvik

django-precise-bbcode Documentation

django cms Documentation

django-sendgrid-events Documentation

django-avatar Documentation

The syndication feed framework

kaleo Documentation Release 1.5 Eldarion

wagtailmenus Documentation

django-amp-tools Documentation Release latest

django-renderit Documentation

django simple pagination Documentation

Django Extra Views Documentation

django-gollum Documentation

The Django Web Framework Part II. Hamid Zarrabi-Zadeh Web Programming Fall 2013

Django: Views, Templates, and Sessions

Moving to a Sustainable Web Development Environment for Library Web Applications

django-sticky-uploads Documentation

TailorDev Contact Documentation

wagtailtrans Documentation

django-password-reset Documentation

Without Django. applying django principles to non django projects

Django Forme Documentation

django-ratelimit-backend Documentation

Django-frontend-notification Documentation

django-osm-field Release 0.3.1

Django Standalone Apps

Building a Django Twilio Programmable Chat Application

micawber Documentation

django-slim Documentation

Django File Picker Documentation

alphafilter Documentation

Umbraco // The Friendly CMS. ezsearch Documentation

EXPERIENCES MOVING FROM DJANGO TO FLASK

CSE 115. Introduction to Computer Science I

django-contact-form Documentation

LECTURE 14. Web Frameworks

Django with Python Course Catalog

colab Documentation Release 2.0dev Sergio Oliveira

Aldryn Documentation. Release Divio AG

django-ajax-form-mixin Documentation

Djam Documentation. Release Participatory Culture Foundation

django-allauth-2fa Documentation

Django urls Django Girls Tutorial

Bricks Documentation. Release 1.0. Germano Guerrini

generates scaffolding/framework for models, views

Design Importer User Guide

Django. Jinja2. Aymeric Augustin DjangoCong 2016

django-simple-sms Documentation

django-stored-messages Documentation

django-image-cropping Documentation

Django Image Tools Documentation

django-push Documentation

django-conduit Documentation

Quick housekeeping Last Two Homeworks Extra Credit for demoing project prototypes Reminder about Project Deadlines/specifics Class on April 12th Resul

Nuit Documentation. Release Ben Cardy

django SHOP Release dev0

django-xross Documentation

Django EL(Endless) Pagination Documentation

SagePay payment gateway package for django-oscar Documentation

Django Test Utils Documentation

django-facebook-graph Documentation

Django Wordpress API Documentation

widgets, events, layout loosely similar to Swing test browser, or plugin for testing with real browser on local system

Webdev: Building Django Apps. Ryan Fox Andrew Glassman MKE Python

Runtime Dynamic Models Documentation Release 1.0

django-audiofield Documentation

Pipeline Documentation

Django Debug Toolbar Documentation

django-embed-video Documentation

CIS192 Python Programming

DJOAuth2 Documentation

Summary. 1. Page 2. Methods 3. Helloworld 4. Translation 5. Layout a. Object b. Table 6. Template 7. Links. Helloworld. Translation Layout.

Django Part II SPARCS 11 undead. Greatly Inspired by SPARCS 10 hodduc

Django PAM Documentation

Bambu Bootstrap Documentation

Django Better Cache Documentation

ska Documentation Release Artur Barseghyan

Application documentation Documentation

django-intranet Documentation

Roxen Content Provider

django-generic-filters Documentation

Django-CSP Documentation

Mantis STIX Importer Documentation

django-embed-video Documentation

django-baton Documentation

django-model-report Documentation

USER MANUAL. SEO Suite TABLE OF CONTENTS. Version: 1.4

HOW TO FLASK. And a very short intro to web development and databases

Writing a Django e- commerce framework OSCON 2012

django-oauth2-provider Documentation

Transcription:

django-cms-search Documentation Release 0.6.2 Divio GmbH February 04, 2016

Contents 1 Requirements 3 2 Usage 5 2.1 Customizing the Index.......................................... 5 3 Helpers 7 3.1 {% get_translated_value %} template tag.......................... 8 4 Settings 9 4.1 CMS_SEARCH_INDEX_BASE_CLASS................................ 9 Python Module Index 11 i

ii

django-cms-search Documentation, Release 0.6.2 This package provides multilingual search indexes for easy Haystack integration with django CMS. Contents 1

django-cms-search Documentation, Release 0.6.2 2 Contents

CHAPTER 1 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 3

django-cms-search Documentation, Release 0.6.2 4 Chapter 1. Requirements

CHAPTER 2 Usage After installing django-cms-search through your package manager of choice, INSTALLED_APPS. That s it. add cms_search to your Warning: Since version 0.5, the HaystackSearchApphook is not registered automatically anymore. If you want do use the default app hook provided by django-cms-search, add this (e.g. in models.py): from cms_search.cms_app import HaystackSearchApphook apphook_pool.register(haystacksearchapphook) For setting up Haystack, please refer to their documentation. 2.1 Customizing the Index You can customize what parts of a CMSPlugin end up in the index with two class attributes on CMSPluginBase subclasses: search_fields a list of field names to index. search_fulltext 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 CMSPlugin. Starting with 0.6, it can also be defined on CMSPluginBase, for cases where one CMSPlugin subclass is used by multiple CMSPluginBase subclasses with different search requirements. 5

django-cms-search Documentation, Release 0.6.2 6 Chapter 2. Usage

CHAPTER 3 Helpers django-cms-search provides a couple of useful helpers to deal with multilingual content. class cms_search.search_helpers.indexes.multilanguageindex A SearchIndex that dynamically adds translated fields to the search index. An example for when this is useful is the app hook infrastructure from django CMS. When a model s get_absolute_url() uses a url pattern that is attached to an app hook, the URL varies depending on the language. A usage example: from haystack import indexes from cms_search.search_helpers.indexes import MultiLanguageIndex class NewsIndex(MultiLanguageIndex): text = indexes.charfield(document=true, use_template=true) title = indexes.charfield(model_attr='title') url = indexes.charfield(stored=true) def prepare_url(self, obj): return obj.get_absolute_url() class HaystackTrans: fields = ('url', 'title') Note: MultiLanguageIndex dynamically creates translated fields. The name of the dynamic fields is a concatenation of the original field name, an underscore and the language code. If you define a prepare() method for a translated field, that method will be called multiple times, with changing active language. In the above example, you might want to catch NoReverseMatch exceptions if you don t have activated the app hook for all languages defined in LANGUAGES. The model_attr attribute is handled somewhat specially. The index tries to find a field on the model called model_attr + _ + language_code. If it exists, it is used as the translated value. But it isn t possible to supply the name of a model method and let the index call it with varying activated languages. Use prepare_myfieldname() for that case. Note: django CMS monkeypatches django.core.urlresolvers.reverse() to enable language namespaces. To ensure that this monkeypatching happens before haystack autodiscovers your indexes, your search_sites.py should look somewhat like this: 7

django-cms-search Documentation, Release 0.6.2 from cms.models import monkeypatch_reverse import haystack monkeypatch_reverse() haystack.autodiscover() class cms_search.search_helpers.fields.multilangtemplatefield A haystack.indexes.charfield subclass that renders the search template in all languages defined in LANGUAGES and concatenates the result. Note: If you plan to render django CMS placeholders in the template, make sure to pass the needs_request argument to cms_search.search_helpers.fields.multilangtemplatefield(). 3.1 {% get_translated_value %} template tag This template tag is most useful in combination with the MultiLanguageIndex. You can use it while looping through search results, and it will automatically pick up the translated field for the current language or fall back to another available language (in the order defined in LANGUAGES). Example: {% load cms_search_tags %} <ul class="search-results"> {% for result in page.object_list %} <li><a href="{% get_translated_value result "url" %}">{% get_translated_value result "title" {% endfor %} </ul> Note: If you plan to use this template tag, you have to add cms_search.search_helpers to your INSTALLED_APPS. 8 Chapter 3. Helpers

CHAPTER 4 Settings 4.1 CMS_SEARCH_INDEX_BASE_CLASS Default: haystack.indexes.searchindex This setting can be used to add custom fields to the search index if the included fields do not suffice. Make sure to provide the full path to your SearchIndex subclass. 9

django-cms-search Documentation, Release 0.6.2 10 Chapter 4. Settings

Python Module Index c cms_search.search_helpers, 7 11

django-cms-search Documentation, Release 0.6.2 12 Python Module Index

Index C cms_search.search_helpers (module), 7 cms_search.search_helpers.fields.multilangtemplatefield (class in cms_search.search_helpers), 8 cms_search.search_helpers.indexes.multilanguageindex (class in cms_search.search_helpers), 7 G get_translated_value template tag, 8 S search_fields, 5 search_fulltext, 5 T template tag get_translated_value, 8 13