diff options
author | Sayan Chowdhury <sayan.chowdhury2012@gmail.com> | 2011-09-28 08:36:14 +0530 |
---|---|---|
committer | Sayan Chowdhury <sayan.chowdhury2012@gmail.com> | 2011-09-28 08:36:14 +0530 |
commit | f67ed6b73eb18750acb921d08f414b5d6af78ef6 (patch) | |
tree | 752d2fba36cf3ffbd6f2223b32fbef40ca929903 /askbot/feed.py | |
parent | b208c5648d4fbf810b65283db4a6eae151839570 (diff) | |
download | askbot-f67ed6b73eb18750acb921d08f414b5d6af78ef6.tar.gz askbot-f67ed6b73eb18750acb921d08f414b5d6af78ef6.tar.bz2 askbot-f67ed6b73eb18750acb921d08f414b5d6af78ef6.zip |
added rss feed for particular question
Diffstat (limited to 'askbot/feed.py')
-rw-r--r-- | askbot/feed.py | 48 |
1 files changed, 47 insertions, 1 deletions
diff --git a/askbot/feed.py b/askbot/feed.py index 23416677..61fd0d3a 100644 --- a/askbot/feed.py +++ b/askbot/feed.py @@ -14,8 +14,54 @@ #encoding:utf-8 from django.contrib.syndication.feeds import Feed from django.utils.translation import ugettext as _ -from askbot.models import Question +from django.core.exceptions import ObjectDoesNotExist +from askbot.models import Question, Answer, Comment from askbot.conf import settings as askbot_settings +import itertools + +class RssParticularQuestionFeed(Feed): + """rss feed class for particular questions + """ + title = askbot_settings.APP_TITLE + _(' - ')+ _('Particular Question') + link = askbot_settings.APP_URL + description = askbot_settings.APP_DESCRIPTION + copyright = askbot_settings.APP_COPYRIGHT + + def get_object(self, bits): + if len(bits) != 1: + raise ObjectDoesNotExist + return Question.objects.get(id__exact = bits[0]) + + def item_link(self, item): + """get full url to the item + """ + return self.link + item.get_absolute_url() + + def item_pubdate(self, item): + """get date of creation for the item + """ + return item.added_at + + def items(self, item): + """get questions for the feed + """ + results = itertools.chain( + Question.objects.filter(id = item.id), + Answer.objects.filter(question = item.id), + Comment.objects.filter(question = item.id), + ) + return results + + def item_title(self, item): + title = item + if item.__class__.__name__ == "Question": + self.title = item + if item.__class__.__name__ == "Answer": + title = "Answer for %s " %self.title + elif item.__class__.__name__ == "Comment": + title = "Comment for %s" %self.title + return title + class RssLastestQuestionsFeed(Feed): """rss feed class for the latest questions """ |