|
0
|
1 |
from django.conf import settings |
|
|
2 |
from django.contrib.syndication.feeds import Feed |
|
|
3 |
from django.contrib.sites.models import Site |
|
|
4 |
from django.contrib import comments |
|
|
5 |
from django.utils.translation import ugettext as _ |
|
|
6 |
|
|
|
7 |
class 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 |