Syndication Feed for JSON
This feed class outputs an existing xml feed as json
- feed
- json
- syndication
This feed class outputs an existing xml feed as json
This snipped provides a subclass of the syndication Feed class that supports HTTP authentication (basic auth). Feeds that should support authentication can inherit from this class instead from the Feed class. It is basically the implementation of [Snippet #243](http://djangosnippets.org/snippets/243/) ported to the new-style syndication framework feeds (for which decorators don't work). Usage: class ArticleFeed(HTTPAuthFeed): def items(self, obj): return Article.objects.all().order_by('-created')[:10] def item_title(self, item): return item.title def item_description(self, item): return item.description
This creates an RSS feed that has "content:encoded" elements for each item in the feed. The "description" is best used for a brief summary of the entry, while the extra ["content:encoded"](http://purl.org/rss/1.0/modules/content#syntax2) element is designed for the entire contents of something. This is the code I'm using for a weblog app. The main features you'd need to copy to add "content:encoded" elements to your own feed are: * **ExtendedRSSFeed()** -- this is used to create a new kind of feed generator class that will know about these extra elements. * **feed_type = ExtendedRSSFeed** -- we tell the feed class which feed generator class to use. * **item_extra_kwargs()** -- we add the "content:encoded" element to each item. This populates the element by calling... * **item_content_encoded()** -- this prepares the actual content. The name doesn't have to be in this format, but it seemed sensible to follow convention. The body of my weblog Entries are split into two parts and here it makes sure we add both parts, both of which contain HTML (which the syndication classes will encode appropriately.
The syndication documentation gives a very basic beginning to creating an iTunes Podcast Feed, but leaves a lot of work left to be figured out. This is a completed example. Because I needed to obtain the duration of the podcast file programmatically (not part of this code) I limit the podcast to mp3 files. If you want to obtain durations some other way you can set the mime_type in the same manner as the other properties. This is what I'm using and should be plenty for you to customize from.
Provides a basic implementation of Yahoo's [MediaRSS](http://video.search.yahoo.com/mrss) format for [Photologue](http://code.google.com/p/django-photologue/) galleries Simplest usage: I have feedgenerator.py in a utils directory. Import photofeeds and hook up the feed url in your URLConf: from utils.feedgenerator import photofeeds urlpatterns += patterns('', url(r'^feeds/(?P<url>.*)/$', 'django.contrib.syndication.views.feed', {'feed_dict': photofeeds}),) Without customization, this will generate a feed for the gallery archive at `/feeds/gallery/` It will contain a single photo per gallery, as returned by Gallery.sample() Additionally, each gallery has a dynamic feed available at the url via Gallery.title_slug: `/feeds/gallery/gallery-title-slug/` This feed will contain an Item for each Photo in the Gallery All that is left is to add an autodiscovery feed to your pages in <head>. An RSS agent like CoolIris can then parse your gallery and provide a slick view of your photos. e.g Add something like this to gallery_detail.html: `<link rel="alternate" href="/feeds/gallery/{{ object.title_slug }}/" type="application/rss+xml" title="Photologue Gallery - {{ object.title }}" id="gallery_feed" /> `
This is a very simple way of getting authenticated RSS feeds in django, by slightly changing the django.contrib.syndication.views 1) copy django/contrib/syndication/views.py into mysite/feeds/views.py 2) replace the contents of that file with the snippet 3) any feeds which you require login just add them to the auth_required list. In this case I require login for /feeds/mystuff/ so I make auth_required = ['mystuff'] My directory structure is like this: mysite/feeds/ views.py feedmodels.py feedmodels.py is just where you make your feed models (see http://docs.djangoproject.com/en/dev/ref/contrib/syndication/ where they give an example of "LatestEntries") [urls.py] - this is what I add in urls.py from mysite.feeds.feedmodels import Latest,MyPersonalStuff feeds = { 'latest':Latest, 'mystuff':MyPersonalStuff, } (r'^feeds/(?P<url>.*)/$', 'mysite.feeds.views.feed', {'feed_dict': feeds}), ###########################################################################
A revisit of [the original snippet](http://www.djangosnippets.org/snippets/311/) with simple caching.
This is an inclusion tag that can be used to pull in posts from any feed to a template. It doesn't do any caching, so it may slow down page load times. Depends on [Feedparser](http://www.feedparser.org). Template usage: {% pull_feed 'http://www.djangosnippets.org/feeds/latest/' 3 %}
This class simplies the Feed class of django. The differences are: 1. Don't need define title and description template file 2. default feed generator class is Atom1Feed 3. According feed_url, EasyFeed can auto get the domain field, and you can also specify the domain parameter.(feed_url should be a full domain path, so you can use [Get the full request path](http://www.djangosnippets.org/snippets/41/) to get the full path of the feed url.) 4. There is a helper function render_feed() to return a response value. example --------- Feed class: class BookCommentsFeed(EasyFeed): def __init__(self, feed_url, book_id): super(BookCommentsFeed, self).__init__(feed_url) self.book_id = book_id self.book = Book.objects.get(id=int(book_id)) def link(self): return '/book/%s' % self.book_id def items(self): return self.book.comment_set.all().order_by('-createtime')[:15] def title(self): return 'Comments of: ' + self.book.title def description(self): return self.book.description def item_link(self, item): return '/book/%s/%s' % (self.book_id, item.chapter.num) def item_description(self, item): return item.content def item_title(self, item): return '#%d Comment for: ' % item.id + item.chapter.title def item_pubdate(self, item): return item.createtime def item_author_name(self, item): return item.username And the view code is: from feeds import * from utils.easyfeed import render_feed from utils.common import get_full_path def bookcomments(request, book_id): return render_feed(BookCommentsFeed(get_full_path(request), book_id))
9 snippets posted so far.