diff --git a/django/contrib/comments/feeds.py b/django/contrib/comments/feeds.py index db4b2f818e8..2e0d4c3dc56 100644 --- a/django/contrib/comments/feeds.py +++ b/django/contrib/comments/feeds.py @@ -1,30 +1,27 @@ -from django.conf import settings from django.contrib.syndication.views import Feed -from django.contrib.sites.models import Site +from django.contrib.sites.models import get_current_site from django.contrib import comments from django.utils.translation import ugettext as _ class LatestCommentFeed(Feed): """Feed of latest comments on the current site.""" + def __call__(self, request, *args, **kwargs): + self.site = get_current_site(request) + return super(LatestCommentFeed, self).__call__(request, *args, **kwargs) + def title(self): - if not hasattr(self, '_site'): - self._site = Site.objects.get_current() - return _("%(site_name)s comments") % dict(site_name=self._site.name) + return _("%(site_name)s comments") % dict(site_name=self.site.name) def link(self): - if not hasattr(self, '_site'): - self._site = Site.objects.get_current() - return "http://%s/" % (self._site.domain) + return "http://%s/" % (self.site.domain) def description(self): - if not hasattr(self, '_site'): - self._site = Site.objects.get_current() - return _("Latest comments on %(site_name)s") % dict(site_name=self._site.name) + return _("Latest comments on %(site_name)s") % dict(site_name=self.site.name) def items(self): qs = comments.get_model().objects.filter( - site__pk = settings.SITE_ID, + site__pk = self.site.pk, is_public = True, is_removed = False, ) diff --git a/tests/regressiontests/comment_tests/tests/feed_tests.py b/tests/regressiontests/comment_tests/tests/feed_tests.py index b15ec0c7b88..1ec316eab80 100644 --- a/tests/regressiontests/comment_tests/tests/feed_tests.py +++ b/tests/regressiontests/comment_tests/tests/feed_tests.py @@ -1,12 +1,32 @@ from __future__ import absolute_import +from django.conf import settings +from django.contrib.comments.models import Comment +from django.contrib.contenttypes.models import ContentType +from django.contrib.sites.models import Site + from . import CommentTestCase +from ..models import Article class CommentFeedTests(CommentTestCase): urls = 'regressiontests.comment_tests.urls' feed_url = '/rss/comments/' + def setUp(self): + site_2 = Site.objects.create(id=settings.SITE_ID+1, + domain="example2.com", name="example2.com") + # A comment for another site + c5 = Comment.objects.create( + content_type = ContentType.objects.get_for_model(Article), + object_pk = "1", + user_name = "Joe Somebody", + user_email = "jsomebody@example.com", + user_url = "http://example.com/~joe/", + comment = "A comment for the second site.", + site = site_2, + ) + def test_feed(self): response = self.client.get(self.feed_url) self.assertEqual(response.status_code, 200) @@ -15,3 +35,4 @@ class CommentFeedTests(CommentTestCase): self.assertContains(response, 'example.com comments') self.assertContains(response, 'http://example.com/') self.assertContains(response, '') + self.assertNotContains(response, "A comment for the second site.") diff --git a/tests/regressiontests/comment_tests/urls.py b/tests/regressiontests/comment_tests/urls.py index b2f676786fe..0a7e8b5fdf6 100644 --- a/tests/regressiontests/comment_tests/urls.py +++ b/tests/regressiontests/comment_tests/urls.py @@ -15,6 +15,7 @@ urlpatterns = patterns('', url(r'^flag/(\d+)/$', views.custom_flag_comment), url(r'^delete/(\d+)/$', views.custom_delete_comment), url(r'^approve/(\d+)/$', views.custom_approve_comment), + url(r'^cr/(\d+)/(.+)/$', 'django.contrib.contenttypes.views.shortcut', name='comments-url-redirect'), ) urlpatterns += patterns('',