1 # -*- coding: utf-8 -*-
2 # This file is part of PrawoKultury, licensed under GNU Affero GPLv3 or later.
3 # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
5 from django.conf import settings
6 from haystack import indexes
7 from fnpdjango.utils.models.translation import add_translatable_index, localize_field
8 from migdal.models import Entry
11 class EntryIndex(indexes.SearchIndex, indexes.Indexable):
12 text = indexes.CharField(
14 model_attr=localize_field('body', settings.LANGUAGE_CODE),
16 date = indexes.DateTimeField(indexed=True, model_attr="date")
17 author = indexes.CharField(model_attr="author")
19 def prepare_date(self, obj):
21 if 'date' in self.prepared_data:
22 date = self.prepared_data['date'].strftime('%Y-%m-%dT%H:%M:%SZ')
29 add_translatable_index(EntryIndex, {
30 'title': indexes.CharField(null=True),
31 'lead': indexes.CharField(null=True),
34 add_translatable_index(EntryIndex, {
35 'title': indexes.CharField(null=True),
36 'lead': indexes.CharField(null=True),
37 'body': indexes.CharField(null=True)
39 (lang for lang in settings.LANGUAGES if lang[0] != settings.LANGUAGE_CODE)