Exemplo n.º 1
0
import datetime
from django.conf import settings
from haystack import indexes
from fnpdjango.utils.models.translation import add_translatable_index, localize_field
from events.models import Event


class EventIndex(indexes.SearchIndex, indexes.Indexable):
    text = indexes.CharField(null=True, model_attr=localize_field("title", settings.LANGUAGE_CODE), document=True)

    def get_model(self):
        return Event


add_translatable_index(EventIndex, {"organizer": indexes.CharField(null=True), "place": indexes.CharField(null=True)})

add_translatable_index(
    EventIndex,
    {"title": indexes.CharField(null=True)},
    (lang for lang in settings.LANGUAGES if lang[0] != settings.LANGUAGE_CODE),
)
Exemplo n.º 2
0
class EntryIndex(indexes.SearchIndex, indexes.Indexable):
    text = indexes.CharField(
        null=True,
        model_attr=localize_field('body', settings.LANGUAGE_CODE),
        document=True)
    date = indexes.DateTimeField(indexed=True, model_attr="date")
    author = indexes.CharField(model_attr="author")

    def prepare_date(self, obj):
        date = u''
        if 'date' in self.prepared_data:
            date = self.prepared_data['date'].strftime('%Y-%m-%dT%H:%M:%SZ')
        return date

    def get_model(self):
        return Entry


add_translatable_index(EntryIndex, {
    'title': indexes.CharField(null=True),
    'lead': indexes.CharField(null=True),
    })

add_translatable_index(EntryIndex, {
    'title': indexes.CharField(null=True),
    'lead': indexes.CharField(null=True),
    'body': indexes.CharField(null=True)
    }, 
    (lang for lang in settings.LANGUAGES if lang[0] != settings.LANGUAGE_CODE)
)
Exemplo n.º 3
0
# -*- coding: utf-8 -*-
# This file is part of PrawoKultury, licensed under GNU Affero GPLv3 or later.
# Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
#
from django.conf import settings
from haystack import indexes
from fnpdjango.utils.models.translation import add_translatable_index, localize_field
from migdal.models import Entry


class EntryIndex(indexes.SearchIndex, indexes.Indexable):
    text = indexes.CharField(null=True, model_attr=localize_field("body", settings.LANGUAGE_CODE), document=True)
    date = indexes.DateTimeField(indexed=True, model_attr="date")
    author = indexes.CharField(model_attr="author")

    def get_model(self):
        return Entry

    def index_queryset(self):
        """Used when the entire index for model is updated."""
        return self.get_model().objects.all()


add_translatable_index(EntryIndex, {"title": indexes.CharField(null=True), "lead": indexes.CharField(null=True)})

add_translatable_index(
    EntryIndex,
    {"title": indexes.CharField(null=True), "lead": indexes.CharField(null=True), "body": indexes.CharField(null=True)},
    (lang for lang in settings.LANGUAGES if lang[0] != settings.LANGUAGE_CODE),
)