Commit | Line | Data |
---|---|---|
5f23ec55 PH |
1 | # encoding: utf-8 |
2 | import datetime | |
3 | ||
4 | from django.core.exceptions import ObjectDoesNotExist | |
5 | from haystack import indexes | |
6 | ||
7 | from .models import Communication, Contribution, Offre | |
8 | ||
099e7f84 PH |
9 | REGIONS = { |
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 | |
24 | class 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 | 45 | class CommunicationIndex(AufIndex, indexes.Indexable): |
5f23ec55 PH |
46 | |
47 | def prepare_section(self, obj): | |
5478d8f9 | 48 | return u"Appel à communications" |
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 | ||
57 | class ContributionIndex(AufIndex, indexes.Indexable): | |
58 | ||
5f23ec55 | 59 | def prepare_section(self, obj): |
5478d8f9 | 60 | return u"Appel à contributions" |
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 | ||
69 | class OffreIndex(AufIndex, indexes.Indexable): | |
70 | ||
5f23ec55 | 71 | def prepare_section(self, obj): |
5478d8f9 | 72 | return u"Appel d'offres" |
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') |