summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSayan Chowdhury <sayan.chowdhury2012@gmail.com>2011-09-28 08:36:14 +0530
committerSayan Chowdhury <sayan.chowdhury2012@gmail.com>2011-09-28 08:36:14 +0530
commitf67ed6b73eb18750acb921d08f414b5d6af78ef6 (patch)
tree752d2fba36cf3ffbd6f2223b32fbef40ca929903
parentb208c5648d4fbf810b65283db4a6eae151839570 (diff)
downloadaskbot-f67ed6b73eb18750acb921d08f414b5d6af78ef6.tar.gz
askbot-f67ed6b73eb18750acb921d08f414b5d6af78ef6.tar.bz2
askbot-f67ed6b73eb18750acb921d08f414b5d6af78ef6.zip
added rss feed for particular question
-rw-r--r--askbot/feed.py48
-rw-r--r--askbot/skins/default/templates/question.html6
-rw-r--r--askbot/urls.py5
3 files changed, 56 insertions, 3 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
"""
diff --git a/askbot/skins/default/templates/question.html b/askbot/skins/default/templates/question.html
index 06cd1332..376cd058 100644
--- a/askbot/skins/default/templates/question.html
+++ b/askbot/skins/default/templates/question.html
@@ -12,6 +12,12 @@
{% endblock %}
{% block content %}
<h1><a href="{{ question.get_absolute_url() }}">{{ question.get_question_title() }}</a></h1>
+<p class="rss">
+ (<a
+ href="{{settings.APP_URL}}/feeds/question/{{ question.id }}"
+ title="{% trans %}subscribe to the questions feed{% endtrans %}"
+ >{% trans %}rss feed{% endtrans %}</a>)
+</p>
<table style="width:100%;" id="question-table" {% if question.deleted %}class="deleted"{%endif%}>
<tr>
<td style="width:30px;vertical-align:top">
diff --git a/askbot/urls.py b/askbot/urls.py
index 54c50d96..8b435c56 100644
--- a/askbot/urls.py
+++ b/askbot/urls.py
@@ -8,7 +8,7 @@ from django.conf.urls.defaults import handler500, handler404
from django.contrib import admin
from django.utils.translation import ugettext as _
from askbot import views
-from askbot.feed import RssLastestQuestionsFeed
+from askbot.feed import RssLastestQuestionsFeed, RssParticularQuestionFeed
from askbot.sitemap import QuestionsSitemap
from askbot.skins.utils import update_media_revision
@@ -16,7 +16,8 @@ admin.autodiscover()
update_media_revision()#needs to be run once, so put it here
feeds = {
- 'rss': RssLastestQuestionsFeed
+ 'rss': RssLastestQuestionsFeed,
+ 'question':RssParticularQuestionFeed
}
sitemaps = {
'questions': QuestionsSitemap