Recheche: Correction des nom de facettes
[auf_framonde.git] / project / framonde / search_indexes.py
CommitLineData
5f23ec55
PH
1# encoding: utf-8
2import datetime
3
4from django.core.exceptions import ObjectDoesNotExist
5from haystack import indexes
6
7from .models import Communication, Contribution, Offre
8
099e7f84
PH
9REGIONS = {
10 '0': 'Internationale',
11 '1': 'Afrique Centrale et des Grands-Lacs',
12 '2': 'Afrique de l\'ouest',
13 '3': 'Amériques',
14 '4': 'Asie-Pacifique',
15 '5': 'Caraïbe',
16 '6': 'Europe centrale et orientale',
17 '7': 'Moyen-Orient',
18 '8': 'Océan Indien',
19 '9': 'Maghreb',
20 '10': 'Europe de l\'Ouest'
21}
22
5f23ec55
PH
23
24class AufIndex(indexes.SearchIndex):
099e7f84
PH
25 text = indexes.NgramField(document=True, use_template=True)
26 title = indexes.NgramField(model_attr='titre', stored=True)
27 region = indexes.FacetField(stored=True)
28 section = indexes.FacetField(stored=True)
29# annee_evenement = indexes.FacetField(stored=True)
30 annee_limite = indexes.FacetField(stored=True)
31 date_pub = indexes.DateField(model_attr='date_pub')
5f23ec55 32
099e7f84
PH
33 def prepare_region(self, obj):
34 return REGIONS[obj.region]
5f23ec55 35
099e7f84
PH
36# def prepare_annee_evenement(self, obj):
37# if obj.date_event is not None:
38# return str(obj.date_event.year)
5f23ec55 39
099e7f84
PH
40 def prepare_annee_limite(self, obj):
41 if obj.date_limite is not None:
42 return str(obj.date_limite.year)
5f23ec55 43
5f23ec55 44
099e7f84 45class CommunicationIndex(AufIndex, indexes.Indexable):
5f23ec55
PH
46
47 def prepare_section(self, obj):
4b599426 48 return u"Appel à communication"
5f23ec55 49
099e7f84
PH
50 def get_model(self):
51 return Communication
5f23ec55
PH
52
53 def index_queryset(self, using=None):
099e7f84 54 return Communication.objects.filter(status=3).order_by('-date_pub')
5f23ec55
PH
55
56
57class ContributionIndex(AufIndex, indexes.Indexable):
58
5f23ec55 59 def prepare_section(self, obj):
4b599426 60 return u"Appel à contribution"
5f23ec55 61
099e7f84
PH
62 def get_model(self):
63 return Contribution
5f23ec55
PH
64
65 def index_queryset(self, using=None):
099e7f84 66 return Contribution.objects.filter(status=3).order_by('-date_pub')
5f23ec55
PH
67
68
69class OffreIndex(AufIndex, indexes.Indexable):
70
5f23ec55 71 def prepare_section(self, obj):
4b599426 72 return u"Appel d'offre"
5f23ec55 73
099e7f84
PH
74 def get_model(self):
75 return Offre
5f23ec55
PH
76
77 def index_queryset(self, using=None):
099e7f84 78 return Offre.objects.filter(status=3).order_by('-date_pub')