Fils RSS pour toutes les briques
[auf_savoirs_en_partage_django.git] / auf_savoirs_en_partage / savoirs / rss.py
CommitLineData
37c3ba94 1# -*- encoding: utf-8 -*-
230671ff
EMS
2from datetime import datetime, date, timedelta
3from dateutil.parser import parse as parse_date
4from dateutil.tz import tzlocal, tzutc
5
79b400f0 6from django.core.urlresolvers import reverse
230671ff
EMS
7from django.contrib.syndication.views import Feed
8
9from chercheurs.forms import ChercheurSearchForm
10from savoirs.forms import RessourceSearchForm, ActualiteSearchForm, EvenementSearchForm
11from sitotheque.forms import SiteSearchForm
12
13class FilChercheurs(Feed):
14 title = "Savoirs en partage - chercheurs"
15 link = "/chercheurs/"
16 description = "Fiches de chercheurs mises à jour récemment sur Savoirs en partage"
17
18 def get_object(self, request):
19 search_form = ChercheurSearchForm(request.GET)
20 return search_form.save(commit=False)
21
22 def items(self, search):
23 min_date = date.today() - timedelta(days=30)
24 return search.run().order_by('-date_modification').filter_date_modification(min=min_date)
25
26 def item_title(self, chercheur):
27 return unicode(chercheur)
28
29 def item_description(self, chercheur):
30 return chercheur.etablissement_display
31
32 def item_link(self, chercheur):
33 return reverse('chercheur', kwargs=dict(id=chercheur.id))
34
35 def item_pubdate(self, chercheur):
36 d = chercheur.date_modification
37 return datetime(d.year, d.month, d.day, tzinfo=tzlocal())
38
39class FilRessources(Feed):
40 title = "Savoirs en partage - ressources"
41 link = "/ressources/"
42 description = "Ressources nouvellement disponibles sur Savoirs en partage"
43
44 def get_object(self, request):
45 search_form = RessourceSearchForm(request.GET)
46 return search_form.save(commit=False)
47
48 def items(self, search):
49 min_date = date.today() - timedelta(days=30)
50 return search.run().order_by('-modified').filter_modified(min=min_date)
51
52 def item_title(self, ressource):
53 return ressource.title
54
55 def item_description(self, ressource):
56 return ressource.description
57
58 def item_author_name(self, ressource):
59 return ressource.creator
60
61 def item_pubdate(self, ressource):
62 try:
63 modified = parse_date(ressource.modified)
64 except ValueError:
65 modified = datetime.now()
66 if modified.tzinfo is None:
67 modified.tzinfo = tzutc()
68 return modified
69
70class FilActualitesBase(Feed):
71
72 def get_object(self, request):
73 search_form = ActualiteSearchForm(request.GET)
74 return search_form.save(commit=False)
75
76 def items(self, search):
77 min_date = date.today() - timedelta(days=30)
78 return search.run().filter_date(min=min_date).order_by('-date')
79
80 def item_title(self, actualite):
81 return actualite.titre
82
83 def item_description(self, actualite):
84 return actualite.texte
85
86 def item_author_name(self, actualite):
87 return actualite.source.nom
88
89 def item_pubdate(self, actualite):
90 d = actualite.date
91 return datetime(d.year, d.month, d.day, tzinfo=tzutc())
92
93class FilActualites(FilActualitesBase):
94 title = "Savoirs en partage - actualités"
95 link = "/actualites/"
96 description = "Actualités récentes sur Savoirs en partage"
97
98 def items(self, search):
99 return FilActualitesBase.items(self, search).filter_type('actu')
100
101class FilAppels(FilActualitesBase):
102 title = "Savoirs en partage - appels d'offres"
103 link = "/appels/"
104 description = "Appels d'offres récents sur Savoirs en partage"
37c3ba94 105
230671ff
EMS
106 def items(self, search):
107 return FilActualitesBase.items(self, search).filter_type('appels')
37c3ba94 108
230671ff
EMS
109class FilEvenements(Feed):
110 title = "Savoirs en partage - agenda"
111 link = "/agenda/"
112 description = "Agenda Savoirs en partage"
113 description_template = 'savoirs/rss_evenement_description.html'
79b400f0 114
230671ff
EMS
115 def get_object(self, request):
116 search_form = EvenementSearchForm(request.GET)
117 return search_form.save(commit=False)
37c3ba94 118
230671ff
EMS
119 def items(self, search):
120 min_date = date.today()
121 max_date = date.today() + timedelta(days=30)
122 return search.run().filter_debut(min=min_date, max=max_date).order_by('-debut')
37c3ba94 123
230671ff
EMS
124 def item_title(self, evenement):
125 return evenement.titre
37c3ba94 126
230671ff
EMS
127 def item_author_name(self, evenement):
128 return ' '.join([evenement.prenom, evenement.nom])
37c3ba94 129
230671ff
EMS
130 def item_author_email(self, evenement):
131 return evenement.courriel
011804bb 132
230671ff
EMS
133class FilSites(Feed):
134 title = "Savoirs en partage - sites"
135 link = "/sites/"
136 description = "Sites récemment ajoutés à Savoirs en partage"
79b400f0 137
230671ff
EMS
138 def get_object(self, request):
139 search_form = SiteSearchForm(request.GET)
140 return search_form.save(commit=False)
79b400f0 141
230671ff
EMS
142 def items(self, search):
143 min_date = date.today() - timedelta(days=365)
144 return search.run().filter_date_maj(min=min_date)
79b400f0 145
230671ff
EMS
146 def item_title(self, site):
147 return site.titre
79b400f0 148
230671ff
EMS
149 def item_description(self, site):
150 return site.description
79b400f0 151
230671ff
EMS
152 def item_author_name(self, site):
153 return site.auteur