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):
|
2007-10-19 09:42:21 +08:00
|
|
|
"""Feed of latest free 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()
|
Merged Unicode branch into trunk (r4952:5608). This should be fully
backwards compatible for all practical purposes.
Fixed #2391, #2489, #2996, #3322, #3344, #3370, #3406, #3432, #3454, #3492, #3582, #3690, #3878, #3891, #3937, #4039, #4141, #4227, #4286, #4291, #4300, #4452, #4702
git-svn-id: http://code.djangoproject.com/svn/django/trunk@5609 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2007-07-04 20:11:04 +08:00
|
|
|
return u"%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()
|
Merged Unicode branch into trunk (r4952:5608). This should be fully
backwards compatible for all practical purposes.
Fixed #2391, #2489, #2996, #3322, #3344, #3370, #3406, #3432, #3454, #3492, #3582, #3690, #3878, #3891, #3937, #4039, #4141, #4227, #4286, #4291, #4300, #4452, #4702
git-svn-id: http://code.djangoproject.com/svn/django/trunk@5609 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2007-07-04 20:11:04 +08:00
|
|
|
return u"Latest comments on %s" % self._site.name
|
2005-11-19 00:20:26 +08:00
|
|
|
|
2007-06-01 19:58:17 +08:00
|
|
|
def get_query_set(self):
|
|
|
|
return self.comments_class.objects.filter(site__pk=settings.SITE_ID, is_public=True)
|
|
|
|
|
2005-11-19 00:20:26 +08:00
|
|
|
def items(self):
|
2007-06-01 19:58:17 +08:00
|
|
|
return self.get_query_set()[:40]
|
2005-11-19 00:20:26 +08:00
|
|
|
|
|
|
|
class LatestCommentsFeed(LatestFreeCommentsFeed):
|
2007-10-19 09:42:21 +08:00
|
|
|
"""Feed of latest comments on the current site."""
|
2006-05-02 09:31:56 +08:00
|
|
|
|
|
|
|
comments_class = Comment
|
|
|
|
|
2007-06-01 19:58:17 +08:00
|
|
|
def get_query_set(self):
|
|
|
|
qs = super(LatestCommentsFeed, self).get_query_set()
|
2006-05-26 12:21:36 +08:00
|
|
|
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
|