2005-11-12 11:44:53 +08:00
|
|
|
from django.contrib.syndication import feeds
|
|
|
|
from django.core.exceptions import Http404
|
|
|
|
from django.utils.httpwrappers import HttpResponse
|
|
|
|
|
|
|
|
def feed(request, url, feed_dict=None):
|
|
|
|
if not feed_dict:
|
|
|
|
raise Http404, "No feeds are registered."
|
|
|
|
|
|
|
|
try:
|
|
|
|
slug, param = url.split('/', 1)
|
|
|
|
except ValueError:
|
|
|
|
slug, param = url, ''
|
|
|
|
|
|
|
|
try:
|
|
|
|
f = feed_dict[slug]
|
|
|
|
except KeyError:
|
|
|
|
raise Http404, "Slug %r isn't registered." % slug
|
|
|
|
|
|
|
|
try:
|
2005-11-14 12:59:20 +08:00
|
|
|
feedgen = f(slug, request.path).get_feed(param)
|
2005-11-12 11:44:53 +08:00
|
|
|
except feeds.FeedDoesNotExist:
|
|
|
|
raise Http404, "Invalid feed parameters. Slug %r is valid, but other parameters, or lack thereof, are not." % slug
|
|
|
|
|
2005-11-13 02:32:12 +08:00
|
|
|
response = HttpResponse(mimetype=feedgen.mime_type)
|
2005-11-12 11:44:53 +08:00
|
|
|
feedgen.write(response, 'utf-8')
|
|
|
|
return response
|