Commit 07ffe781 authored by Claude Paroz's avatar Claude Paroz
Browse files

Used get_current_site in comments feed class

parent b8244c65
Loading
Loading
Loading
Loading
+9 −12
Original line number Diff line number Diff line
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,
        )
+21 −0
Original line number Diff line number Diff line
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, '<title>example.com comments</title>')
        self.assertContains(response, '<link>http://example.com/</link>')
        self.assertContains(response, '</rss>')
        self.assertNotContains(response, "A comment for the second site.")
+1 −0
Original line number Diff line number Diff line
@@ -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('',