app/django/contrib/comments/feeds.py
author Todd Larsen <tlarsen@google.com>
Fri, 03 Oct 2008 01:32:34 +0000
changeset 263 9b39d93b677f
parent 54 03e267d67478
child 323 ff1a9aa48cfd
permissions -rw-r--r--
Make findNearestUsers() code in soc/logic/site/id_user.py more generic and move it to soc/logic/model.py. Orginal findNearest...() functions in id_user.py are now convenience wrappers. Add typed-query string construction functions to model.py. Move getFulLClassName() from key_name.py model.py, since it has more to do with Model types than key names. Swap 'offset' and 'limit' and make 'limit' arguments non-optional. Also, stop adding 1 inside the ...ForLimitAndOffset() functions and make the callers do it (since it was being added for a very UI-specific reason of whether or not to display a "Next>" link). Patch by: Todd Larsen Review by: Pawel Solyga Review URL: http://codereviews.googleopensourceprograms.com/1401

from django.conf import settings
from django.contrib.comments.models import Comment, FreeComment
from django.contrib.syndication.feeds import Feed
from django.contrib.sites.models import Site

class LatestFreeCommentsFeed(Feed):
    """Feed of latest free comments on the current site."""

    comments_class = FreeComment

    def title(self):
        if not hasattr(self, '_site'):
            self._site = Site.objects.get_current()
        return u"%s comments" % self._site.name

    def link(self):
        if not hasattr(self, '_site'):
            self._site = Site.objects.get_current()
        return "http://%s/" % (self._site.domain)

    def description(self):
        if not hasattr(self, '_site'):
            self._site = Site.objects.get_current()
        return u"Latest comments on %s" % self._site.name

    def get_query_set(self):
        return self.comments_class.objects.filter(site__pk=settings.SITE_ID, is_public=True)

    def items(self):
        return self.get_query_set()[:40]

class LatestCommentsFeed(LatestFreeCommentsFeed):
    """Feed of latest comments on the current site."""

    comments_class = Comment

    def get_query_set(self):
        qs = super(LatestCommentsFeed, self).get_query_set()
        qs = qs.filter(is_removed=False)
        if settings.COMMENTS_BANNED_USERS_GROUP:
            where = ['user_id NOT IN (SELECT user_id FROM auth_users_group WHERE group_id = %s)']
            params = [settings.COMMENTS_BANNED_USERS_GROUP]
            qs = qs.extra(where=where, params=params)
        return qs