]> git.openstreetmap.org Git - osqa.git/blobdiff - forum/feed.py
OSQA-349
[osqa.git] / forum / feed.py
index e4b929e97e526682da0f648451b5a75e2d21657b..15a8ab9da366e97e7ae307e198dfe146ecc92268 100644 (file)
@@ -1,28 +1,36 @@
-#!/usr/bin/env python
-#encoding:utf-8
-#-------------------------------------------------------------------------------
-# Name:        Syndication feed class for subsribtion
-# Purpose:
-#
-# Author:      Mike
-#
-# Created:     29/01/2009
-# Copyright:   (c) CNPROG.COM 2009
-# Licence:     GPL V2
-#-------------------------------------------------------------------------------
-from django.contrib.syndication.feeds import Feed, FeedDoesNotExist
+try:
+    from django.contrib.syndication.views import Feed, FeedDoesNotExist
+    old_version = False
+except:
+    from django.contrib.syndication.feeds import Feed, FeedDoesNotExist
+    old_version = True
+
+from django.http import HttpResponse
 from django.utils.translation import ugettext as _
 from models import Question
 from django.utils.translation import ugettext as _
 from models import Question
-from django.conf import settings
-class RssLastestQuestionsFeed(Feed):
-    title = settings.APP_TITLE + _(' - ')+ _('latest questions')
-    link = settings.APP_URL #+ '/' + _('question/')
-    description = settings.APP_DESCRIPTION
-    #ttl = 10
+from forum import settings
+
+
+class RssQuestionFeed(Feed):
     copyright = settings.APP_COPYRIGHT
 
     copyright = settings.APP_COPYRIGHT
 
+    def __init__(self, question_list, title, description, request):
+        self._title = title
+        self._description = description
+        self._question_list = question_list
+        self._url = request.path + "&" + "&".join(["%s=%s" % (k, v) for k, v in request.GET.items() if not k in ('page', 'pagesize', 'sort')])
+
+        if old_version:
+            super(RssQuestionFeed, self).__init__('', request)
+
+    def title(self):
+        return self._title
+
+    def link(self):
+        return self._url
+
     def item_link(self, item):
     def item_link(self, item):
-        return self.link + item.get_absolute_url()
+        return item.get_absolute_url()
 
     def item_author_name(self, item):
         return item.author.username
 
     def item_author_name(self, item):
         return item.author.username
@@ -33,11 +41,16 @@ class RssLastestQuestionsFeed(Feed):
     def item_pubdate(self, item):
         return item.added_at
 
     def item_pubdate(self, item):
         return item.added_at
 
-    def items(self, item):
-       return Question.objects.filter(deleted=False).order_by('-last_activity_at')[:30]
+    def item_categories(self, item):
+        return item.tagname_list()  
 
 
-def main():
-    pass
+    def items(self, item):
+       return self._question_list[:30]
 
 
-if __name__ == '__main__':
-    main()
+    if old_version:
+        def __call__(self, request):
+            feedgen = self.get_feed('')
+            response = HttpResponse(mimetype=feedgen.mime_type)
+            feedgen.write(response, 'utf-8')
+            return response
+