~kkubasik/django/aggregation-branch

« back to all changes in this revision

Viewing changes to django/contrib/comments/feeds.py

  • Committer: adrian
  • Date: 2006-05-02 01:31:56 UTC
  • Revision ID: vcs-imports@canonical.com-20060502013156-2941fcd40d080649
MERGED MAGIC-REMOVAL BRANCH TO TRUNK. This change is highly backwards-incompatible. Please read http://code.djangoproject.com/wiki/RemovingTheMagic for upgrade instructions.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
6
6
 
7
7
class LatestFreeCommentsFeed(Feed):
8
8
    """Feed of latest comments on the current site"""
9
 
    
10
 
    comments_module = freecomments
11
 
    
 
9
 
 
10
    comments_class = FreeComment
 
11
 
12
12
    def title(self):
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
16
 
        
 
16
 
17
17
    def link(self):
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)
21
 
    
 
21
 
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
26
26
 
27
27
    def items(self):
28
 
        return self.comments_module.get_list(**self._get_lookup_kwargs())
 
28
        return self.comments_class.objects.filter(**self._get_lookup_kwargs())
29
29
 
30
30
    def _get_lookup_kwargs(self):
31
31
        return {
32
 
            'site__pk' : settings.SITE_ID,
33
 
            'is_public__exact' : True,
34
 
            'limit' : 40,
 
32
            'site__pk': settings.SITE_ID,
 
33
            'is_public__exact': True,
 
34
            'limit': 40,
35
35
        }
36
36
 
37
37
class LatestCommentsFeed(LatestFreeCommentsFeed):
38
38
    """Feed of latest free comments on the current site"""
39
 
    
40
 
    comments_module = comments
41
 
    
 
39
 
 
40
    comments_class = Comment
 
41
 
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]
48
 
        return kwargs
 
 
b'\\ No newline at end of file'
 
48
        return kwargs