Skip to content

Commit

Permalink
Fixed #24728 -- Renamed mime_type to content_type for syndication feeds
Browse files Browse the repository at this point in the history
Renamed the mime_type properties of RssFeed and Atom1Feed to
content_type and start deprecation for the old names.
  • Loading branch information
raphaelm authored and timgraham committed Jun 4, 2015
1 parent 3e9b5bf commit 5c125f6
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 5 deletions.
2 changes: 1 addition & 1 deletion django/contrib/syndication/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def __call__(self, request, *args, **kwargs):
except ObjectDoesNotExist:
raise Http404('Feed object does not exist.')
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 item_pubdate or item_updateddate is defined for the feed, set
# header so as ConditionalGetMiddleware is able to send 304 NOT MODIFIED
Expand Down
24 changes: 22 additions & 2 deletions django/utils/feedgenerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@
from __future__ import unicode_literals

import datetime
import warnings

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.six import StringIO
from django.utils.six.moves.urllib.parse import urlparse
Expand Down Expand Up @@ -219,7 +221,7 @@ def __init__(self, url, length, mime_type):


class RssFeed(SyndicationFeed):
mime_type = 'application/rss+xml; charset=utf-8'
content_type = 'application/rss+xml; charset=utf-8'

def write(self, outfile, encoding):
handler = SimplerXMLGenerator(outfile, encoding)
Expand Down Expand Up @@ -261,6 +263,15 @@ def add_root_elements(self, handler):
def endChannelElement(self, handler):
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):
_version = "0.91"
Expand Down Expand Up @@ -318,7 +329,7 @@ def add_item_elements(self, handler, item):

class Atom1Feed(SyndicationFeed):
# 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"

def write(self, outfile, encoding):
Expand Down Expand Up @@ -410,6 +421,15 @@ def add_item_elements(self, handler, item):
if item['item_copyright'] is not None:
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
# do "feedgenerator.DefaultFeed" instead of "feedgenerator.Rss201rev2Feed".
DefaultFeed = Rss201rev2Feed
4 changes: 4 additions & 0 deletions docs/internals/deprecation.txt
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ details on these changes.
* Support for custom error views with a single positional parameter will be
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:

2.0
Expand Down
4 changes: 4 additions & 0 deletions docs/releases/1.9.txt
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,10 @@ Miscellaneous
signatures with only one request parameter are deprecated. The views should
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:

Features removed in 1.9
Expand Down
4 changes: 2 additions & 2 deletions tests/utils_tests/test_feedgenerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def test_atom1_mime_type(self):
"""
atom_feed = feedgenerator.Atom1Feed("title", "link", "description")
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):
Expand All @@ -98,7 +98,7 @@ def test_rss_mime_type(self):
"""
rss_feed = feedgenerator.Rss201rev2Feed("title", "link", "description")
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
Expand Down

0 comments on commit 5c125f6

Please sign in to comment.