Commit 5c125f63 authored by Raphael Michel's avatar Raphael Michel Committed by Tim Graham
Browse files

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.
parent 3e9b5bfd
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -39,7 +39,7 @@ class Feed(object):
        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
+22 −2
Original line number Diff line number Diff line
@@ -24,8 +24,10 @@ http://web.archive.org/web/20110718035220/http://diveintomark.org/archives/2004/
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
@@ -219,7 +221,7 @@ class Enclosure(object):


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)
@@ -261,6 +263,15 @@ class RssFeed(SyndicationFeed):
    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"
@@ -318,7 +329,7 @@ class Rss201rev2Feed(RssFeed):

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):
@@ -410,6 +421,15 @@ class Atom1Feed(SyndicationFeed):
        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 −0
Original line number Diff line number Diff line
@@ -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
+4 −0
Original line number Diff line number Diff line
@@ -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
+2 −2
Original line number Diff line number Diff line
@@ -89,7 +89,7 @@ class FeedgeneratorTest(unittest.TestCase):
        """
        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):
@@ -98,7 +98,7 @@ class FeedgeneratorTest(unittest.TestCase):
        """
        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