Advanced deprecations in contrib.syndication.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@15976 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
5d5149cd18
commit
24b7d9017d
|
@ -1,38 +0,0 @@
|
||||||
from django.contrib.syndication import views
|
|
||||||
from django.core.exceptions import ObjectDoesNotExist
|
|
||||||
import warnings
|
|
||||||
|
|
||||||
# This is part of the deprecated API
|
|
||||||
from django.contrib.syndication.views import FeedDoesNotExist, add_domain
|
|
||||||
|
|
||||||
class Feed(views.Feed):
|
|
||||||
"""Provided for backwards compatibility."""
|
|
||||||
def __init__(self, slug, request):
|
|
||||||
warnings.warn('The syndication feeds.Feed class is deprecated. Please '
|
|
||||||
'use the new class based view API.',
|
|
||||||
category=DeprecationWarning)
|
|
||||||
|
|
||||||
self.slug = slug
|
|
||||||
self.request = request
|
|
||||||
self.feed_url = getattr(self, 'feed_url', None) or request.path
|
|
||||||
self.title_template = self.title_template or ('feeds/%s_title.html' % slug)
|
|
||||||
self.description_template = self.description_template or ('feeds/%s_description.html' % slug)
|
|
||||||
|
|
||||||
def get_object(self, bits):
|
|
||||||
return None
|
|
||||||
|
|
||||||
def get_feed(self, url=None):
|
|
||||||
"""
|
|
||||||
Returns a feedgenerator.DefaultFeed object, fully populated, for
|
|
||||||
this feed. Raises FeedDoesNotExist for invalid parameters.
|
|
||||||
"""
|
|
||||||
if url:
|
|
||||||
bits = url.split('/')
|
|
||||||
else:
|
|
||||||
bits = []
|
|
||||||
try:
|
|
||||||
obj = self.get_object(bits)
|
|
||||||
except ObjectDoesNotExist:
|
|
||||||
raise FeedDoesNotExist
|
|
||||||
return super(Feed, self).get_feed(obj, self.request)
|
|
||||||
|
|
|
@ -183,47 +183,3 @@ class Feed(object):
|
||||||
**self.item_extra_kwargs(item)
|
**self.item_extra_kwargs(item)
|
||||||
)
|
)
|
||||||
return feed
|
return feed
|
||||||
|
|
||||||
|
|
||||||
def feed(request, url, feed_dict=None):
|
|
||||||
"""Provided for backwards compatibility."""
|
|
||||||
from django.contrib.syndication.feeds import Feed as LegacyFeed
|
|
||||||
import warnings
|
|
||||||
warnings.warn('The syndication feed() view is deprecated. Please use the '
|
|
||||||
'new class based view API.',
|
|
||||||
category=DeprecationWarning)
|
|
||||||
|
|
||||||
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)
|
|
||||||
|
|
||||||
# Backwards compatibility within the backwards compatibility;
|
|
||||||
# Feeds can be updated to be class-based, but still be deployed
|
|
||||||
# using the legacy feed view. This only works if the feed takes
|
|
||||||
# no arguments (i.e., get_object returns None). Refs #14176.
|
|
||||||
if not issubclass(f, LegacyFeed):
|
|
||||||
instance = f()
|
|
||||||
instance.feed_url = getattr(f, 'feed_url', None) or request.path
|
|
||||||
instance.title_template = f.title_template or ('feeds/%s_title.html' % slug)
|
|
||||||
instance.description_template = f.description_template or ('feeds/%s_description.html' % slug)
|
|
||||||
|
|
||||||
return instance(request)
|
|
||||||
|
|
||||||
try:
|
|
||||||
feedgen = f(slug, request).get_feed(param)
|
|
||||||
except FeedDoesNotExist:
|
|
||||||
raise Http404("Invalid feed parameters. Slug %r is valid, but other parameters, or lack thereof, are not." % slug)
|
|
||||||
|
|
||||||
response = HttpResponse(mimetype=feedgen.mime_type)
|
|
||||||
feedgen.write(response, 'utf-8')
|
|
||||||
return response
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue