2005-11-19 00:20:26 +08:00
|
|
|
from django.conf import settings
|
2006-05-02 09:31:56 +08:00
|
|
|
from django.contrib.comments.models import Comment, FreeComment
|
2005-11-19 00:20:26 +08:00
|
|
|
from django.contrib.syndication.feeds import Feed
|
2006-05-02 09:31:56 +08:00
|
|
|
from django.contrib.sites.models import Site
|
2005-11-19 00:20:26 +08:00
|
|
|
|
|
|
|
class LatestFreeCommentsFeed(Feed):
|
2006-05-26 12:21:36 +08:00
|
|
|
"Feed of latest comments on the current site."
|
2006-05-02 09:31:56 +08:00
|
|
|
|
|
|
|
comments_class = FreeComment
|
|
|
|
|
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()
|
2005-11-19 00:20:26 +08:00
|
|
|
return "%s comments" % 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()
|
2005-11-19 00:20:26 +08:00
|
|
|
return "Latest comments on %s" % self._site.name
|
|
|
|
|
|
|
|
def items(self):
|
2006-05-26 12:21:36 +08:00
|
|
|
return self.comments_class.objects.filter(site__pk=settings.SITE_ID, is_public=True)[:40]
|
2005-11-19 00:20:26 +08:00
|
|
|
|
|
|
|
class LatestCommentsFeed(LatestFreeCommentsFeed):
|
|
|
|
"""Feed of latest free comments on the current site"""
|
2006-05-02 09:31:56 +08:00
|
|
|
|
|
|
|
comments_class = Comment
|
|
|
|
|
2006-05-26 12:21:36 +08:00
|
|
|
def items(self):
|
|
|
|
qs = LatestFreeCommentsFeed.items(self)
|
|
|
|
qs = qs.filter(is_removed=False)
|
2005-11-19 00:20:26 +08:00
|
|
|
if settings.COMMENTS_BANNED_USERS_GROUP:
|
2006-05-26 12:21:36 +08:00
|
|
|
where = ['user_id NOT IN (SELECT user_id FROM auth_users_group 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)
|
|
|
|
return qs
|