SEESenv/web/hgbook/comments/feeds.py
author amit@thunder
Sun, 28 Feb 2010 19:25:01 +0530
changeset 36 a542eb905ced
parent 2 52d12eb31c30
permissions -rwxr-xr-x
Testing
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
     1
from django.core.exceptions import ObjectDoesNotExist
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
     2
from django.utils.feedgenerator import Atom1Feed
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
     3
from django.contrib.syndication.feeds import Feed
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
     4
from hgbook.comments.models import Comment, Element
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
     5
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
     6
class MyAtomFeed(Atom1Feed):
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
     7
    title_type = u'html'
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
     8
    
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
     9
class Comments(Feed):
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    10
    feed_type = MyAtomFeed
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    11
    title = 'Mercurial - The Definitive Guide: recent comments'
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    12
    subtitle = ('Recent comments on the text of “Mercurial: The '
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    13
                'Definitive Guide”, from our readers')
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    14
    link = '/feeds/comments/'
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    15
    author_name = 'Our readers'
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    16
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    17
    def feedfilter(self, queryset):
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    18
        return queryset.order_by('-date')[:20]
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    19
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    20
    def items(self):
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    21
        return self.feedfilter(Comment.objects)
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    22
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    23
    def item_author_name(self, obj):
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    24
        return obj.submitter_name
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    25
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    26
    def item_pubdate(self, obj):
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    27
        return obj.date
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    28
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    29
    def get_object(self, bits):
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    30
        if len(bits) == 0:
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    31
            return self.items()
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    32
        elif len(bits) > 1:
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    33
            raise ObjectDoesNotExist
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    34
        return self.feedfilter(Comment.objects.filter(element__chapter=bits[0],
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    35
                                                      hidden=False))