1 # -*- encoding: utf-8 -*-
2 from datetime
import datetime
, date
, timedelta
3 from dateutil
.parser
import parse
as parse_date
4 from dateutil
.tz
import tzlocal
, tzutc
6 from django
.core
.urlresolvers
import reverse
7 from django
.contrib
.syndication
.views
import Feed
9 from chercheurs
.forms
import ChercheurSearchForm
10 from savoirs
.forms
import RessourceSearchForm
, ActualiteSearchForm
, EvenementSearchForm
11 from sitotheque
.forms
import SiteSearchForm
13 class FilChercheurs(Feed
):
14 title
= "Savoirs en partage - chercheurs"
16 description
= "Fiches de chercheurs mises à jour récemment sur Savoirs en partage"
18 def get_object(self
, request
):
19 search_form
= ChercheurSearchForm(request
.GET
)
20 return search_form
.save(commit
=False)
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
)
26 def item_title(self
, chercheur
):
27 return unicode(chercheur
)
29 def item_description(self
, chercheur
):
30 return chercheur
.etablissement_display
32 def item_link(self
, chercheur
):
33 return reverse('chercheur', kwargs
=dict(id=chercheur
.id))
35 def item_pubdate(self
, chercheur
):
36 d
= chercheur
.date_modification
37 return datetime(d
.year
, d
.month
, d
.day
, tzinfo
=tzlocal())
39 class FilRessources(Feed
):
40 title
= "Savoirs en partage - ressources"
42 description
= "Ressources nouvellement disponibles sur Savoirs en partage"
44 def get_object(self
, request
):
45 search_form
= RessourceSearchForm(request
.GET
)
46 return search_form
.save(commit
=False)
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
)
52 def item_title(self
, ressource
):
53 return ressource
.title
55 def item_description(self
, ressource
):
56 return ressource
.description
58 def item_author_name(self
, ressource
):
59 return ressource
.creator
61 def item_pubdate(self
, ressource
):
63 modified
= parse_date(ressource
.modified
)
65 modified
= datetime
.now()
66 if modified
.tzinfo
is None:
67 modified
.tzinfo
= tzutc()
70 class FilActualitesBase(Feed
):
72 def get_object(self
, request
):
73 search_form
= ActualiteSearchForm(request
.GET
)
74 return search_form
.save(commit
=False)
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')
80 def item_title(self
, actualite
):
81 return actualite
.titre
83 def item_description(self
, actualite
):
84 return actualite
.texte
86 def item_author_name(self
, actualite
):
87 return actualite
.source
.nom
89 def item_pubdate(self
, actualite
):
91 return datetime(d
.year
, d
.month
, d
.day
, tzinfo
=tzutc())
93 class FilActualites(FilActualitesBase
):
94 title
= "Savoirs en partage - actualités"
96 description
= "Actualités récentes sur Savoirs en partage"
98 def items(self
, search
):
99 return FilActualitesBase
.items(self
, search
).filter_type('actu')
101 class FilAppels(FilActualitesBase
):
102 title
= "Savoirs en partage - appels d'offres"
104 description
= "Appels d'offres récents sur Savoirs en partage"
106 def items(self
, search
):
107 return FilActualitesBase
.items(self
, search
).filter_type('appels')
109 class FilEvenements(Feed
):
110 title
= "Savoirs en partage - agenda"
112 description
= "Agenda Savoirs en partage"
113 description_template
= 'savoirs/rss_evenement_description.html'
115 def get_object(self
, request
):
116 search_form
= EvenementSearchForm(request
.GET
)
117 return search_form
.save(commit
=False)
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')
124 def item_title(self
, evenement
):
125 return evenement
.titre
127 def item_author_name(self
, evenement
):
128 return ' '.join([evenement
.prenom
, evenement
.nom
])
130 def item_author_email(self
, evenement
):
131 return evenement
.courriel
133 class FilSites(Feed
):
134 title
= "Savoirs en partage - sites"
136 description
= "Sites récemment ajoutés à Savoirs en partage"
138 def get_object(self
, request
):
139 search_form
= SiteSearchForm(request
.GET
)
140 return search_form
.save(commit
=False)
142 def items(self
, search
):
143 min_date
= date
.today() - timedelta(days
=365)
144 return search
.run().filter_date_maj(min=min_date
)
146 def item_title(self
, site
):
149 def item_description(self
, site
):
150 return site
.description
152 def item_author_name(self
, site
):