RSS feed with content:encoded elements

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
from django.contrib.syndication.views import Feed
from django.utils.feedgenerator import Rss201rev2Feed
from django.shortcuts import get_object_or_404
from weblog.models import Blog,Entry


class ExtendedRSSFeed(Rss201rev2Feed):
    """
    Create a type of RSS feed that has content:encoded elements.
    """
    def root_attributes(self):
        attrs = super(ExtendedRSSFeed, self).root_attributes()
        attrs['xmlns:content'] = 'http://purl.org/rss/1.0/modules/content/'
        return attrs
        
    def add_item_elements(self, handler, item):
        super(ExtendedRSSFeed, self).add_item_elements(handler, item)
        handler.addQuickElement(u'content:encoded', item['content_encoded'])


class LatestEntriesFeed(Feed):

    feed_type = ExtendedRSSFeed

    def get_object(self, request, blog_slug):
        return get_object_or_404(Blog, slug=blog_slug)

    # Elements for the top-level, channel.
    
    def title(self, obj):
        return obj.name

    def link(self, obj):
        return obj.get_absolute_url()

    def description(self, obj):
        return obj.description


    def items(self):
        return Entry.live.all()[:5]

    def item_extra_kwargs(self, item):
        return {'content_encoded': self.item_content_encoded(item)}


    # Elements for each item.
    
    def item_title(self, item):
        return item.title

    def item_description(self, item):
        return item.excerpt

    def item_author_name(self, item):
        if (item.author.get_full_name()):
            return item.author.get_full_name()
        else:
            return item.author

    def item_pubdate(self, item):
        return item.published_date

    def item_content_encoded(self, item):
        content = item.body_html
        if (item.body_more_html):
            content += item.body_more_html
        return content

More like this

  1. HTTP (basic) auth enabled (new-style) syndication framework feed class by hupf 2 years, 5 months ago
  2. Media RSS generation for Photologue by ltvolks 3 years, 10 months ago
  3. RSS feed authentication by rileycrane 3 years, 10 months ago
  4. EasyFeed class by limodou 6 years, 2 months ago
  5. FieldsetForm by Ciantic 6 years, 1 month ago

Comments

(Forgotten your password?)