1
1
from django.conf import settings
2
from django.contrib.comments.models import Comment, FreeComment
2
3
from django.contrib.syndication.feeds import Feed
3
4
from django.core.exceptions import ObjectDoesNotExist
4
from django.models.core import sites
5
from django.models.comments import comments, freecomments
5
from django.contrib.sites.models import Site
7
7
class LatestFreeCommentsFeed(Feed):
8
8
"""Feed of latest comments on the current site"""
10
comments_module = freecomments
10
comments_class = FreeComment
13
13
if not hasattr(self, '_site'):
14
self._site = sites.get_current()
14
self._site = Site.objects.get_current()
15
15
return "%s comments" % self._site.name
18
18
if not hasattr(self, '_site'):
19
self._site = sites.get_current()
19
self._site = Site.objects.get_current()
20
20
return "http://%s/" % (self._site.domain)
22
22
def description(self):
23
23
if not hasattr(self, '_site'):
24
self._site = sites.get_current()
24
self._site = Site.objects.get_current()
25
25
return "Latest comments on %s" % self._site.name
28
return self.comments_module.get_list(**self._get_lookup_kwargs())
28
return self.comments_class.objects.filter(**self._get_lookup_kwargs())
30
30
def _get_lookup_kwargs(self):
32
'site__pk' : settings.SITE_ID,
33
'is_public__exact' : True,
32
'site__pk': settings.SITE_ID,
33
'is_public__exact': True,
37
37
class LatestCommentsFeed(LatestFreeCommentsFeed):
38
38
"""Feed of latest free comments on the current site"""
40
comments_module = comments
40
comments_class = Comment
42
42
def _get_lookup_kwargs(self):
43
43
kwargs = LatestFreeCommentsFeed._get_lookup_kwargs(self)
44
44
kwargs['is_removed__exact'] = False
45
45
if settings.COMMENTS_BANNED_USERS_GROUP:
46
46
kwargs['where'] = ['user_id NOT IN (SELECT user_id FROM auth_users_group WHERE group_id = %s)']
47
47
kwargs['params'] = [COMMENTS_BANNED_USERS_GROUP]
b'\\ No newline at end of file'