mirror of https://github.com/django/django.git
Fixed #24728 -- Renamed mime_type to content_type for syndication feeds
Renamed the mime_type properties of RssFeed and Atom1Feed to content_type and start deprecation for the old names.
This commit is contained in:
parent
3e9b5bfd9c
commit
5c125f63f7
|
@ -39,7 +39,7 @@ class Feed(object):
|
||||||
except ObjectDoesNotExist:
|
except ObjectDoesNotExist:
|
||||||
raise Http404('Feed object does not exist.')
|
raise Http404('Feed object does not exist.')
|
||||||
feedgen = self.get_feed(obj, request)
|
feedgen = self.get_feed(obj, request)
|
||||||
response = HttpResponse(content_type=feedgen.mime_type)
|
response = HttpResponse(content_type=feedgen.content_type)
|
||||||
if hasattr(self, 'item_pubdate') or hasattr(self, 'item_updateddate'):
|
if hasattr(self, 'item_pubdate') or hasattr(self, 'item_updateddate'):
|
||||||
# if item_pubdate or item_updateddate is defined for the feed, set
|
# if item_pubdate or item_updateddate is defined for the feed, set
|
||||||
# header so as ConditionalGetMiddleware is able to send 304 NOT MODIFIED
|
# header so as ConditionalGetMiddleware is able to send 304 NOT MODIFIED
|
||||||
|
|
|
@ -24,8 +24,10 @@ http://web.archive.org/web/20110718035220/http://diveintomark.org/archives/2004/
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
import datetime
|
import datetime
|
||||||
|
import warnings
|
||||||
|
|
||||||
from django.utils import datetime_safe, six
|
from django.utils import datetime_safe, six
|
||||||
|
from django.utils.deprecation import RemovedInDjango21Warning
|
||||||
from django.utils.encoding import force_text, iri_to_uri
|
from django.utils.encoding import force_text, iri_to_uri
|
||||||
from django.utils.six import StringIO
|
from django.utils.six import StringIO
|
||||||
from django.utils.six.moves.urllib.parse import urlparse
|
from django.utils.six.moves.urllib.parse import urlparse
|
||||||
|
@ -219,7 +221,7 @@ class Enclosure(object):
|
||||||
|
|
||||||
|
|
||||||
class RssFeed(SyndicationFeed):
|
class RssFeed(SyndicationFeed):
|
||||||
mime_type = 'application/rss+xml; charset=utf-8'
|
content_type = 'application/rss+xml; charset=utf-8'
|
||||||
|
|
||||||
def write(self, outfile, encoding):
|
def write(self, outfile, encoding):
|
||||||
handler = SimplerXMLGenerator(outfile, encoding)
|
handler = SimplerXMLGenerator(outfile, encoding)
|
||||||
|
@ -261,6 +263,15 @@ class RssFeed(SyndicationFeed):
|
||||||
def endChannelElement(self, handler):
|
def endChannelElement(self, handler):
|
||||||
handler.endElement("channel")
|
handler.endElement("channel")
|
||||||
|
|
||||||
|
@property
|
||||||
|
def mime_type(self):
|
||||||
|
warnings.warn(
|
||||||
|
'The mime_type attribute of RssFeed is deprecated. '
|
||||||
|
'Use content_type instead.',
|
||||||
|
RemovedInDjango21Warning, stacklevel=2
|
||||||
|
)
|
||||||
|
return self.content_type
|
||||||
|
|
||||||
|
|
||||||
class RssUserland091Feed(RssFeed):
|
class RssUserland091Feed(RssFeed):
|
||||||
_version = "0.91"
|
_version = "0.91"
|
||||||
|
@ -318,7 +329,7 @@ class Rss201rev2Feed(RssFeed):
|
||||||
|
|
||||||
class Atom1Feed(SyndicationFeed):
|
class Atom1Feed(SyndicationFeed):
|
||||||
# Spec: http://atompub.org/2005/07/11/draft-ietf-atompub-format-10.html
|
# Spec: http://atompub.org/2005/07/11/draft-ietf-atompub-format-10.html
|
||||||
mime_type = 'application/atom+xml; charset=utf-8'
|
content_type = 'application/atom+xml; charset=utf-8'
|
||||||
ns = "http://www.w3.org/2005/Atom"
|
ns = "http://www.w3.org/2005/Atom"
|
||||||
|
|
||||||
def write(self, outfile, encoding):
|
def write(self, outfile, encoding):
|
||||||
|
@ -410,6 +421,15 @@ class Atom1Feed(SyndicationFeed):
|
||||||
if item['item_copyright'] is not None:
|
if item['item_copyright'] is not None:
|
||||||
handler.addQuickElement("rights", item['item_copyright'])
|
handler.addQuickElement("rights", item['item_copyright'])
|
||||||
|
|
||||||
|
@property
|
||||||
|
def mime_type(self):
|
||||||
|
warnings.warn(
|
||||||
|
'The mime_type attribute of Atom1Feed is deprecated. '
|
||||||
|
'Use content_type instead.',
|
||||||
|
RemovedInDjango21Warning, stacklevel=2
|
||||||
|
)
|
||||||
|
return self.content_type
|
||||||
|
|
||||||
# This isolates the decision of what the system default is, so calling code can
|
# This isolates the decision of what the system default is, so calling code can
|
||||||
# do "feedgenerator.DefaultFeed" instead of "feedgenerator.Rss201rev2Feed".
|
# do "feedgenerator.DefaultFeed" instead of "feedgenerator.Rss201rev2Feed".
|
||||||
DefaultFeed = Rss201rev2Feed
|
DefaultFeed = Rss201rev2Feed
|
||||||
|
|
|
@ -66,6 +66,10 @@ details on these changes.
|
||||||
* Support for custom error views with a single positional parameter will be
|
* Support for custom error views with a single positional parameter will be
|
||||||
dropped.
|
dropped.
|
||||||
|
|
||||||
|
* The ``mime_type`` attribute of ``django.utils.feedgenerator.Atom1Feed`` and
|
||||||
|
``django.utils.feedgenerator.RssFeed`` will be removed in favor of
|
||||||
|
``content_type``.
|
||||||
|
|
||||||
.. _deprecation-removed-in-2.0:
|
.. _deprecation-removed-in-2.0:
|
||||||
|
|
||||||
2.0
|
2.0
|
||||||
|
|
|
@ -641,6 +641,10 @@ Miscellaneous
|
||||||
signatures with only one request parameter are deprecated. The views should
|
signatures with only one request parameter are deprecated. The views should
|
||||||
now also accept a second ``exception`` positional parameter.
|
now also accept a second ``exception`` positional parameter.
|
||||||
|
|
||||||
|
* The ``django.utils.feedgenerator.Atom1Feed.mime_type`` and
|
||||||
|
``django.utils.feedgenerator.RssFeed.mime_type`` attributes are deprecated in
|
||||||
|
favor of ``content_type``.
|
||||||
|
|
||||||
.. removed-features-1.9:
|
.. removed-features-1.9:
|
||||||
|
|
||||||
Features removed in 1.9
|
Features removed in 1.9
|
||||||
|
|
|
@ -89,7 +89,7 @@ class FeedgeneratorTest(unittest.TestCase):
|
||||||
"""
|
"""
|
||||||
atom_feed = feedgenerator.Atom1Feed("title", "link", "description")
|
atom_feed = feedgenerator.Atom1Feed("title", "link", "description")
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
atom_feed.mime_type, "application/atom+xml; charset=utf-8"
|
atom_feed.content_type, "application/atom+xml; charset=utf-8"
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_rss_mime_type(self):
|
def test_rss_mime_type(self):
|
||||||
|
@ -98,7 +98,7 @@ class FeedgeneratorTest(unittest.TestCase):
|
||||||
"""
|
"""
|
||||||
rss_feed = feedgenerator.Rss201rev2Feed("title", "link", "description")
|
rss_feed = feedgenerator.Rss201rev2Feed("title", "link", "description")
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
rss_feed.mime_type, "application/rss+xml; charset=utf-8"
|
rss_feed.content_type, "application/rss+xml; charset=utf-8"
|
||||||
)
|
)
|
||||||
|
|
||||||
# Two regression tests for #14202
|
# Two regression tests for #14202
|
||||||
|
|
Loading…
Reference in New Issue