]> git.openstreetmap.org Git - osqa.git/blob - forum/feed.py
Removes some unsused context variables, and removes the books module which was not...
[osqa.git] / forum / feed.py
1 try:
2     from django.contrib.syndication.views import Feed, FeedDoesNotExist
3     old_version = False
4 except:
5     from django.contrib.syndication.feeds import Feed, FeedDoesNotExist
6     old_version = True
7
8 from django.http import HttpResponse
9 from django.utils.translation import ugettext as _
10 from models import Question
11 from forum import settings
12
13
14 class RssQuestionFeed(Feed):
15     copyright = settings.APP_COPYRIGHT
16
17     def __init__(self, question_list, title, description, request):
18         self._title = title
19         self._description = description
20         self._question_list = question_list
21         self._url = request.path + "&" + "&".join(["%s=%s" % (k, v) for k, v in request.GET.items() if not k in ('page', 'pagesize', 'sort')])
22
23         if old_version:
24             super(RssQuestionFeed, self).__init__('', request)
25
26     def title(self):
27         return self._title
28
29     def link(self):
30         return self._url
31
32     def item_link(self, item):
33         return item.get_absolute_url()
34
35     def item_author_name(self, item):
36         return item.author.username
37
38     def item_author_link(self, item):
39         return item.author.get_profile_url()
40
41     def item_pubdate(self, item):
42         return item.added_at
43
44     def item_categories(self, item):
45         return item.tagname_list()  
46
47     def items(self, item):
48        return self._question_list[:30]
49
50     if old_version:
51         def __call__(self, request):
52             feedgen = self.get_feed('')
53             response = HttpResponse(mimetype=feedgen.mime_type)
54             feedgen.write(response, 'utf-8')
55             return response
56