app/django/contrib/comments/feeds.py
changeset 54 03e267d67478
child 323 ff1a9aa48cfd
equal deleted inserted replaced
53:57b4279d8c4e 54:03e267d67478
       
     1 from django.conf import settings
       
     2 from django.contrib.comments.models import Comment, FreeComment
       
     3 from django.contrib.syndication.feeds import Feed
       
     4 from django.contrib.sites.models import Site
       
     5 
       
     6 class LatestFreeCommentsFeed(Feed):
       
     7     """Feed of latest free comments on the current site."""
       
     8 
       
     9     comments_class = FreeComment
       
    10 
       
    11     def title(self):
       
    12         if not hasattr(self, '_site'):
       
    13             self._site = Site.objects.get_current()
       
    14         return u"%s comments" % self._site.name
       
    15 
       
    16     def link(self):
       
    17         if not hasattr(self, '_site'):
       
    18             self._site = Site.objects.get_current()
       
    19         return "http://%s/" % (self._site.domain)
       
    20 
       
    21     def description(self):
       
    22         if not hasattr(self, '_site'):
       
    23             self._site = Site.objects.get_current()
       
    24         return u"Latest comments on %s" % self._site.name
       
    25 
       
    26     def get_query_set(self):
       
    27         return self.comments_class.objects.filter(site__pk=settings.SITE_ID, is_public=True)
       
    28 
       
    29     def items(self):
       
    30         return self.get_query_set()[:40]
       
    31 
       
    32 class LatestCommentsFeed(LatestFreeCommentsFeed):
       
    33     """Feed of latest comments on the current site."""
       
    34 
       
    35     comments_class = Comment
       
    36 
       
    37     def get_query_set(self):
       
    38         qs = super(LatestCommentsFeed, self).get_query_set()
       
    39         qs = qs.filter(is_removed=False)
       
    40         if settings.COMMENTS_BANNED_USERS_GROUP:
       
    41             where = ['user_id NOT IN (SELECT user_id FROM auth_users_group WHERE group_id = %s)']
       
    42             params = [settings.COMMENTS_BANNED_USERS_GROUP]
       
    43             qs = qs.extra(where=where, params=params)
       
    44         return qs