PageRenderTime 81ms CodeModel.GetById 40ms app.highlight 4ms RepoModel.GetById 36ms app.codeStats 0ms

/django/contrib/comments/feeds.py

https://code.google.com/p/mango-py/
Python | 38 lines | 31 code | 6 blank | 1 comment | 7 complexity | 1693538c643012fec8172e8e9ed5a94f MD5 | raw file
 1from django.conf import settings
 2from django.contrib.syndication.views import Feed
 3from django.contrib.sites.models import Site
 4from django.contrib import comments
 5from django.utils.translation import ugettext as _
 6
 7class LatestCommentFeed(Feed):
 8    """Feed of latest comments on the current site."""
 9
10    def title(self):
11        if not hasattr(self, '_site'):
12            self._site = Site.objects.get_current()
13        return _("%(site_name)s comments") % dict(site_name=self._site.name)
14
15    def link(self):
16        if not hasattr(self, '_site'):
17            self._site = Site.objects.get_current()
18        return "http://%s/" % (self._site.domain)
19
20    def description(self):
21        if not hasattr(self, '_site'):
22            self._site = Site.objects.get_current()
23        return _("Latest comments on %(site_name)s") % dict(site_name=self._site.name)
24
25    def items(self):
26        qs = comments.get_model().objects.filter(
27            site__pk = settings.SITE_ID,
28            is_public = True,
29            is_removed = False,
30        )
31        if getattr(settings, 'COMMENTS_BANNED_USERS_GROUP', None):
32            where = ['user_id NOT IN (SELECT user_id FROM auth_user_groups WHERE group_id = %s)']
33            params = [settings.COMMENTS_BANNED_USERS_GROUP]
34            qs = qs.extra(where=where, params=params)
35        return qs.order_by('-submit_date')[:40]
36
37    def item_pubdate(self, item):
38        return item.submit_date