2010-01-28 21:46:18 +08:00
|
|
|
from django.contrib.syndication.views import Feed
|
2012-09-28 20:35:26 +08:00
|
|
|
from django.contrib.sites.models import get_current_site
|
2008-08-26 06:14:22 +08:00
|
|
|
from django.contrib import comments
|
2009-04-08 03:57:01 +08:00
|
|
|
from django.utils.translation import ugettext as _
|
2005-11-19 00:20:26 +08:00
|
|
|
|
2008-08-26 06:14:22 +08:00
|
|
|
class LatestCommentFeed(Feed):
|
|
|
|
"""Feed of latest comments on the current site."""
|
2006-05-02 09:31:56 +08:00
|
|
|
|
2012-09-28 20:35:26 +08:00
|
|
|
def __call__(self, request, *args, **kwargs):
|
|
|
|
self.site = get_current_site(request)
|
|
|
|
return super(LatestCommentFeed, self).__call__(request, *args, **kwargs)
|
|
|
|
|
2005-11-19 00:20:26 +08:00
|
|
|
def title(self):
|
2012-09-28 20:35:26 +08:00
|
|
|
return _("%(site_name)s comments") % dict(site_name=self.site.name)
|
2006-05-02 09:31:56 +08:00
|
|
|
|
2005-11-19 00:20:26 +08:00
|
|
|
def link(self):
|
2012-09-28 20:35:26 +08:00
|
|
|
return "http://%s/" % (self.site.domain)
|
2006-05-02 09:31:56 +08:00
|
|
|
|
2005-11-19 00:20:26 +08:00
|
|
|
def description(self):
|
2012-09-28 20:35:26 +08:00
|
|
|
return _("Latest comments on %(site_name)s") % dict(site_name=self.site.name)
|
2005-11-19 00:20:26 +08:00
|
|
|
|
|
|
|
def items(self):
|
2008-08-26 06:14:22 +08:00
|
|
|
qs = comments.get_model().objects.filter(
|
2012-09-28 20:35:26 +08:00
|
|
|
site__pk = self.site.pk,
|
2008-08-26 06:14:22 +08:00
|
|
|
is_public = True,
|
|
|
|
is_removed = False,
|
|
|
|
)
|
2008-09-28 10:50:09 +08:00
|
|
|
return qs.order_by('-submit_date')[:40]
|
2010-01-28 21:46:18 +08:00
|
|
|
|
2008-08-26 06:14:22 +08:00
|
|
|
def item_pubdate(self, item):
|
2008-09-28 10:50:09 +08:00
|
|
|
return item.submit_date
|