2005-11-19 00:20:26 +08:00
|
|
|
from django.conf import settings
|
2010-01-28 21:46:18 +08:00
|
|
|
from django.contrib.syndication.views import Feed
|
2006-05-02 09:31:56 +08:00
|
|
|
from django.contrib.sites.models import 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
|
|
|
|
2005-11-19 00:20:26 +08:00
|
|
|
def title(self):
|
|
|
|
if not hasattr(self, '_site'):
|
2006-05-02 09:31:56 +08:00
|
|
|
self._site = Site.objects.get_current()
|
2009-04-08 03:57:01 +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):
|
|
|
|
if not hasattr(self, '_site'):
|
2006-05-02 09:31:56 +08:00
|
|
|
self._site = Site.objects.get_current()
|
2005-11-19 00:20: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):
|
|
|
|
if not hasattr(self, '_site'):
|
2006-05-02 09:31:56 +08:00
|
|
|
self._site = Site.objects.get_current()
|
2009-04-08 03:57:01 +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(
|
|
|
|
site__pk = settings.SITE_ID,
|
|
|
|
is_public = True,
|
|
|
|
is_removed = False,
|
|
|
|
)
|
|
|
|
if getattr(settings, 'COMMENTS_BANNED_USERS_GROUP', None):
|
2008-09-28 10:55:56 +08:00
|
|
|
where = ['user_id NOT IN (SELECT user_id FROM auth_user_groups WHERE group_id = %s)']
|
2006-07-22 03:12:51 +08:00
|
|
|
params = [settings.COMMENTS_BANNED_USERS_GROUP]
|
2006-05-26 12:21:36 +08:00
|
|
|
qs = qs.extra(where=where, params=params)
|
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
|