4 from django
.core
.exceptions
import ObjectDoesNotExist
5 from haystack
import indexes
7 from .models
import Communication
, Contribution
, Offre
10 '0': 'Internationale',
11 '1': 'Afrique Centrale et des Grands-Lacs',
12 '2': 'Afrique de l\'ouest',
14 '4': 'Asie-Pacifique',
16 '6': 'Europe centrale et orientale',
20 '10': 'Europe de l\'Ouest'
24 class AufIndex(indexes
.SearchIndex
):
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')
33 def prepare_region(self
, obj
):
34 return REGIONS
[obj
.region
]
36 # def prepare_annee_evenement(self, obj):
37 # if obj.date_event is not None:
38 # return str(obj.date_event.year)
40 def prepare_annee_limite(self
, obj
):
41 if obj
.date_limite
is not None:
42 return str(obj
.date_limite
.year
)
45 class CommunicationIndex(AufIndex
, indexes
.Indexable
):
47 def prepare_section(self
, obj
):
48 return u
"Appel à communications"
53 def index_queryset(self
, using
=None):
54 return Communication
.objects
.filter(status
=3).order_by('-date_pub')
57 class ContributionIndex(AufIndex
, indexes
.Indexable
):
59 def prepare_section(self
, obj
):
60 return u
"Appel à contributions"
65 def index_queryset(self
, using
=None):
66 return Contribution
.objects
.filter(status
=3).order_by('-date_pub')
69 class OffreIndex(AufIndex
, indexes
.Indexable
):
71 def prepare_section(self
, obj
):
72 return u
"Appel d'offres"
77 def index_queryset(self
, using
=None):
78 return Offre
.objects
.filter(status
=3).order_by('-date_pub')