RSS pour les messages de groupe
[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 7from django.contrib.syndication.views import Feed
bf2904f0
PP
8from django.shortcuts import get_object_or_404
9
230671ff
EMS
10
11from chercheurs.forms import ChercheurSearchForm
12from savoirs.forms import RessourceSearchForm, ActualiteSearchForm, EvenementSearchForm
13from sitotheque.forms import SiteSearchForm
14
bf2904f0
PP
15from chercheurs.models import Groupe, Message
16
230671ff
EMS
17class FilChercheurs(Feed):
18 title = "Savoirs en partage - chercheurs"
19 link = "/chercheurs/"
20 description = "Fiches de chercheurs mises à jour récemment sur Savoirs en partage"
21
22 def get_object(self, request):
23 search_form = ChercheurSearchForm(request.GET)
24 return search_form.save(commit=False)
25
26 def items(self, search):
27 min_date = date.today() - timedelta(days=30)
4b89a7df 28 return search.run(min_date=min_date).order_by('-date_modification')
230671ff
EMS
29
30 def item_title(self, chercheur):
31 return unicode(chercheur)
32
33 def item_description(self, chercheur):
34 return chercheur.etablissement_display
35
36 def item_link(self, chercheur):
37 return reverse('chercheur', kwargs=dict(id=chercheur.id))
38
39 def item_pubdate(self, chercheur):
40 d = chercheur.date_modification
41 return datetime(d.year, d.month, d.day, tzinfo=tzlocal())
42
43class FilRessources(Feed):
44 title = "Savoirs en partage - ressources"
45 link = "/ressources/"
46 description = "Ressources nouvellement disponibles sur Savoirs en partage"
47
48 def get_object(self, request):
49 search_form = RessourceSearchForm(request.GET)
50 return search_form.save(commit=False)
51
52 def items(self, search):
53 min_date = date.today() - timedelta(days=30)
4b89a7df 54 return search.run(min_date=min_date).order_by('-modified')
230671ff
EMS
55
56 def item_title(self, ressource):
57 return ressource.title
58
59 def item_description(self, ressource):
60 return ressource.description
61
62 def item_author_name(self, ressource):
63 return ressource.creator
64
65 def item_pubdate(self, ressource):
66 try:
67 modified = parse_date(ressource.modified)
68 except ValueError:
69 modified = datetime.now()
70 if modified.tzinfo is None:
71 modified.tzinfo = tzutc()
72 return modified
73
74class FilActualitesBase(Feed):
75
76 def get_object(self, request):
77 search_form = ActualiteSearchForm(request.GET)
78 return search_form.save(commit=False)
79
80 def items(self, search):
81 min_date = date.today() - timedelta(days=30)
4b89a7df 82 return search.run(min_date=min_date).order_by('-date')
230671ff
EMS
83
84 def item_title(self, actualite):
85 return actualite.titre
86
87 def item_description(self, actualite):
88 return actualite.texte
89
90 def item_author_name(self, actualite):
91 return actualite.source.nom
92
93 def item_pubdate(self, actualite):
94 d = actualite.date
95 return datetime(d.year, d.month, d.day, tzinfo=tzutc())
96
97class FilActualites(FilActualitesBase):
98 title = "Savoirs en partage - actualités"
99 link = "/actualites/"
100 description = "Actualités récentes sur Savoirs en partage"
101
102 def items(self, search):
103 return FilActualitesBase.items(self, search).filter_type('actu')
104
105class FilAppels(FilActualitesBase):
106 title = "Savoirs en partage - appels d'offres"
107 link = "/appels/"
108 description = "Appels d'offres récents sur Savoirs en partage"
37c3ba94 109
230671ff
EMS
110 def items(self, search):
111 return FilActualitesBase.items(self, search).filter_type('appels')
37c3ba94 112
230671ff
EMS
113class FilEvenements(Feed):
114 title = "Savoirs en partage - agenda"
115 link = "/agenda/"
116 description = "Agenda Savoirs en partage"
117 description_template = 'savoirs/rss_evenement_description.html'
79b400f0 118
230671ff
EMS
119 def get_object(self, request):
120 search_form = EvenementSearchForm(request.GET)
121 return search_form.save(commit=False)
37c3ba94 122
230671ff 123 def items(self, search):
a83b8efb
EMS
124 min_date = date.today() - timedelta(days=30)
125 return search.run(min_date=min_date).order_by('-debut')
37c3ba94 126
230671ff
EMS
127 def item_title(self, evenement):
128 return evenement.titre
37c3ba94 129
230671ff
EMS
130 def item_author_name(self, evenement):
131 return ' '.join([evenement.prenom, evenement.nom])
37c3ba94 132
230671ff
EMS
133 def item_author_email(self, evenement):
134 return evenement.courriel
011804bb 135
230671ff
EMS
136class FilSites(Feed):
137 title = "Savoirs en partage - sites"
138 link = "/sites/"
139 description = "Sites récemment ajoutés à Savoirs en partage"
79b400f0 140
230671ff
EMS
141 def get_object(self, request):
142 search_form = SiteSearchForm(request.GET)
143 return search_form.save(commit=False)
79b400f0 144
230671ff 145 def items(self, search):
4b89a7df
EMS
146 min_date = date.today() - timedelta(days=30)
147 return search.run(min_date=min_date)
79b400f0 148
230671ff
EMS
149 def item_title(self, site):
150 return site.titre
79b400f0 151
230671ff
EMS
152 def item_description(self, site):
153 return site.description
79b400f0 154
230671ff
EMS
155 def item_author_name(self, site):
156 return site.auteur
bf2904f0
PP
157
158class FilMessages(Feed):
159
160 def get_object(self, request, groupe_id):
161 return get_object_or_404(Groupe, pk=groupe_id)
162
163 def title(self, obj):
164 return "Savoirs en partage - Messages pour le groupe: %s" % (obj.nom,)
165
166 def link(self, obj):
167 return obj.get_absolute_url()
168
169 def description(self, obj):
170 return "Derniers messages du groupe %s" % (obj.nom,)
171
172 def items(self, obj):
173 return Message.objects.filter(groupe=obj)[:30]
174
175 def item_title(self, message):
176 return message.titre
177
178 def item_description(self, message):
179 return message.contenu
180
181 def item_author_name(self, message):
182 return message.chercheur