Code

Ticket #19692: 19692-2.diff

File 19692-2.diff, 15.5 KB (added by aaugustin, 15 months ago)
Line 
1diff --git a/django/contrib/sitemaps/views.py b/django/contrib/sitemaps/views.py
2index cfe3aa6..c8d2f4d 100644
3--- a/django/contrib/sitemaps/views.py
4+++ b/django/contrib/sitemaps/views.py
5@@ -1,3 +1,5 @@
6+import warnings
7+
8 from django.contrib.sites.models import get_current_site
9 from django.core import urlresolvers
10 from django.core.paginator import EmptyPage, PageNotAnInteger
11@@ -6,8 +8,15 @@ from django.template.response import TemplateResponse
12 from django.utils import six
13 
14 def index(request, sitemaps,
15-          template_name='sitemap_index.xml', mimetype='application/xml',
16-          sitemap_url_name='django.contrib.sitemaps.views.sitemap'):
17+          template_name='sitemap_index.xml', content_type='application/xml',
18+          sitemap_url_name='django.contrib.sitemaps.views.sitemap',
19+          mimetype=None):
20+
21+    if mimetype:
22+        warnings.warn("The mimetype keyword argument is deprecated, use "
23+            "content_type instead", DeprecationWarning, stacklevel=2)
24+        content_type = mimetype
25+
26     req_protocol = 'https' if request.is_secure() else 'http'
27     req_site = get_current_site(request)
28 
29@@ -24,10 +33,17 @@ def index(request, sitemaps,
30             sites.append('%s?p=%s' % (absolute_url, page))
31 
32     return TemplateResponse(request, template_name, {'sitemaps': sites},
33-                            content_type=mimetype)
34+                            content_type=content_type)
35 
36 def sitemap(request, sitemaps, section=None,
37-            template_name='sitemap.xml', mimetype='application/xml'):
38+            template_name='sitemap.xml', content_type='application/xml',
39+            mimetype=None):
40+
41+    if mimetype:
42+        warnings.warn("The mimetype keyword argument is deprecated, use "
43+            "content_type instead", DeprecationWarning, stacklevel=2)
44+        content_type = mimetype
45+
46     req_protocol = 'https' if request.is_secure() else 'http'
47     req_site = get_current_site(request)
48 
49@@ -51,4 +67,4 @@ def sitemap(request, sitemaps, section=None,
50         except PageNotAnInteger:
51             raise Http404("No page '%s'" % page)
52     return TemplateResponse(request, template_name, {'urlset': urls},
53-                            content_type=mimetype)
54+                            content_type=content_type)
55diff --git a/django/shortcuts/__init__.py b/django/shortcuts/__init__.py
56index 9f89634..21bd7a0 100644
57--- a/django/shortcuts/__init__.py
58+++ b/django/shortcuts/__init__.py
59@@ -3,6 +3,7 @@ This module collects helper functions and classes that "span" multiple levels
60 of MVC. In other words, these functions/classes introduce controlled coupling
61 for convenience's sake.
62 """
63+import warnings
64 
65 from django.template import loader, RequestContext
66 from django.http import HttpResponse, Http404
67@@ -17,7 +18,14 @@ def render_to_response(*args, **kwargs):
68     Returns a HttpResponse whose content is filled with the result of calling
69     django.template.loader.render_to_string() with the passed arguments.
70     """
71-    httpresponse_kwargs = {'content_type': kwargs.pop('mimetype', None)}
72+    httpresponse_kwargs = {'content_type': kwargs.pop('content_type', None)}
73+
74+    mimetype = kwargs.pop('mimetype', None)
75+    if mimetype:
76+        warnings.warn("The mimetype keyword argument is deprecated, use "
77+            "content_type instead", DeprecationWarning, stacklevel=2)
78+        httpresponse_kwargs['content_type'] = mimetype
79+
80     return HttpResponse(loader.render_to_string(*args, **kwargs), **httpresponse_kwargs)
81 
82 def render(request, *args, **kwargs):
83diff --git a/docs/howto/outputting-csv.txt b/docs/howto/outputting-csv.txt
84index bcc6f38..1f9efb5 100644
85--- a/docs/howto/outputting-csv.txt
86+++ b/docs/howto/outputting-csv.txt
87@@ -20,7 +20,7 @@ Here's an example::
88 
89     def some_view(request):
90         # Create the HttpResponse object with the appropriate CSV header.
91-        response = HttpResponse(mimetype='text/csv')
92+        response = HttpResponse(content_type='text/csv')
93         response['Content-Disposition'] = 'attachment; filename="somefilename.csv"'
94 
95         writer = csv.writer(response)
96@@ -92,7 +92,7 @@ Here's an example, which generates the same CSV file as above::
97 
98     def some_view(request):
99         # Create the HttpResponse object with the appropriate CSV header.
100-        response = HttpResponse(mimetype='text/csv')
101+        response = HttpResponse(content_type='text/csv')
102         response['Content-Disposition'] = 'attachment; filename="somefilename.csv"'
103 
104         # The data is hard-coded here, but you could load it from a database or
105@@ -111,7 +111,7 @@ Here's an example, which generates the same CSV file as above::
106 
107 The only difference between this example and the previous example is that this
108 one uses template loading instead of the CSV module. The rest of the code --
109-such as the ``mimetype='text/csv'`` -- is the same.
110+such as the ``content_type='text/csv'`` -- is the same.
111 
112 Then, create the template ``my_template_name.txt``, with this template code:
113 
114diff --git a/docs/howto/outputting-pdf.txt b/docs/howto/outputting-pdf.txt
115index 9d87b97..d15f94f 100644
116--- a/docs/howto/outputting-pdf.txt
117+++ b/docs/howto/outputting-pdf.txt
118@@ -51,7 +51,7 @@ Here's a "Hello World" example::
119 
120     def some_view(request):
121         # Create the HttpResponse object with the appropriate PDF headers.
122-        response = HttpResponse(mimetype='application/pdf')
123+        response = HttpResponse(content_type='application/pdf')
124         response['Content-Disposition'] = 'attachment; filename="somefilename.pdf"'
125 
126         # Create the PDF object, using the response object as its "file."
127@@ -120,7 +120,7 @@ Here's the above "Hello World" example rewritten to use :mod:`io`::
128 
129     def some_view(request):
130         # Create the HttpResponse object with the appropriate PDF headers.
131-        response = HttpResponse(mimetype='application/pdf')
132+        response = HttpResponse(content_type='application/pdf')
133         response['Content-Disposition'] = 'attachment; filename="somefilename.pdf"'
134 
135         buffer = BytesIO()
136diff --git a/docs/internals/deprecation.txt b/docs/internals/deprecation.txt
137index 63d65d1..da0d1e2 100644
138--- a/docs/internals/deprecation.txt
139+++ b/docs/internals/deprecation.txt
140@@ -290,8 +290,14 @@ these changes.
141   specified as a plain string instead of a tuple will be removed and raise an
142   exception.
143 
144-* The ``mimetype`` argument to :class:`~django.http.HttpResponse` ``__init__``
145-  will be removed (``content_type`` should be used instead).
146+* The ``mimetype`` argument to the ``__init__`` methods of
147+  :class:`~django.http.HttpResponse`,
148+  :class:`~django.template.response.SimpleTemplateResponse`, and
149+  :class:`~django.template.response.TemplateResponse`, will be removed.
150+  ``content_type`` should be used instead. This also applies to the
151+  :func:`~django.shortcuts.render_to_response` shortcut and
152+  the sitemamp views, :func:`~django.contrib.sitemaps.views.index` and
153+  :func:`~django.contrib.sitemaps.views.sitemap`.
154 
155 * When :class:`~django.http.HttpResponse` is instantiated with an iterator,
156   or when :attr:`~django.http.HttpResponse.content` is set to an iterator,
157diff --git a/docs/ref/contrib/admin/actions.txt b/docs/ref/contrib/admin/actions.txt
158index d7eef62..0a302ec 100644
159--- a/docs/ref/contrib/admin/actions.txt
160+++ b/docs/ref/contrib/admin/actions.txt
161@@ -223,7 +223,7 @@ objects as JSON::
162     from django.core import serializers
163 
164     def export_as_json(modeladmin, request, queryset):
165-        response = HttpResponse(mimetype="text/javascript")
166+        response = HttpResponse(content_type="application/json")
167         serializers.serialize("json", queryset, stream=response)
168         return response
169 
170@@ -356,5 +356,3 @@ Conditionally enabling or disabling actions
171                     if 'delete_selected' in actions:
172                         del actions['delete_selected']
173                 return actions
174-
175-
176diff --git a/docs/ref/template-response.txt b/docs/ref/template-response.txt
177index 3f5e772..844b5fa 100644
178--- a/docs/ref/template-response.txt
179+++ b/docs/ref/template-response.txt
180@@ -56,11 +56,11 @@ Attributes
181 Methods
182 -------
183 
184-.. method:: SimpleTemplateResponse.__init__(template, context=None, mimetype=None, status=None, content_type=None)
185+.. method:: SimpleTemplateResponse.__init__(template, context=None, content_type=None, status=None)
186 
187     Instantiates a
188     :class:`~django.template.response.SimpleTemplateResponse` object
189-    with the given template, context, MIME type and HTTP status.
190+    with the given template, context, content type, and HTTP status.
191 
192     ``template``
193         The full name of a template, or a sequence of template names.
194@@ -75,12 +75,15 @@ Methods
195         The HTTP Status code for the response.
196 
197     ``content_type``
198-        An alias for ``mimetype``. Historically, this parameter was only called
199-        ``mimetype``, but since this is actually the value included in the HTTP
200-        ``Content-Type`` header, it can also include the character set encoding,
201-        which makes it more than just a MIME type specification. If ``mimetype``
202-        is specified (not ``None``), that value is used. Otherwise,
203-        ``content_type`` is used. If neither is given,
204+
205+        .. versionchanged:: 1.5
206+
207+        Historically, this parameter was only called ``mimetype`` (now
208+        deprecated), but since this is actually the value included in the HTTP
209+        ``Content-Type`` header, it can also include the character set
210+        encoding, which makes it more than just a MIME type specification. If
211+        ``mimetype`` is specified (not ``None``), that value is used.
212+        Otherwise, ``content_type`` is used. If neither is given,
213         :setting:`DEFAULT_CONTENT_TYPE` is used.
214 
215 
216@@ -144,7 +147,7 @@ TemplateResponse objects
217 Methods
218 -------
219 
220-.. method:: TemplateResponse.__init__(request, template, context=None, mimetype=None, status=None, content_type=None, current_app=None)
221+.. method:: TemplateResponse.__init__(request, template, context=None, content_type=None, status=None, current_app=None)
222 
223     Instantiates an ``TemplateResponse`` object with the given
224     template, context, MIME type and HTTP status.
225@@ -165,12 +168,15 @@ Methods
226         The HTTP Status code for the response.
227 
228     ``content_type``
229-        An alias for ``mimetype``. Historically, this parameter was only called
230-        ``mimetype``, but since this is actually the value included in the HTTP
231-        ``Content-Type`` header, it can also include the character set encoding,
232-        which makes it more than just a MIME type specification. If ``mimetype``
233-        is specified (not ``None``), that value is used. Otherwise,
234-        ``content_type`` is used. If neither is given,
235+
236+        .. versionchanged:: 1.5
237+
238+        Historically, this parameter was only called ``mimetype`` (now
239+        deprecated), but since this is actually the value included in the HTTP
240+        ``Content-Type`` header, it can also include the character set
241+        encoding, which makes it more than just a MIME type specification. If
242+        ``mimetype`` is specified (not ``None``), that value is used.
243+        Otherwise, ``content_type`` is used. If neither is given,
244         :setting:`DEFAULT_CONTENT_TYPE` is used.
245 
246     ``current_app``
247diff --git a/docs/topics/http/shortcuts.txt b/docs/topics/http/shortcuts.txt
248index b1b4700..68860f1 100644
249--- a/docs/topics/http/shortcuts.txt
250+++ b/docs/topics/http/shortcuts.txt
251@@ -50,6 +50,9 @@ Optional arguments
252     The MIME type to use for the resulting document. Defaults to the value of
253     the :setting:`DEFAULT_CONTENT_TYPE` setting.
254 
255+    .. versionchanged:: 1.5
256+        This parameter used to be called ``mimetype``.
257+
258 ``status``
259     The status code for the response. Defaults to ``200``.
260 
261@@ -87,7 +90,7 @@ This example is equivalent to::
262 ``render_to_response``
263 ======================
264 
265-.. function:: render_to_response(template_name[, dictionary][, context_instance][, mimetype])
266+.. function:: render_to_response(template_name[, dictionary][, context_instance][, content_type])
267 
268    Renders a given template with a given context dictionary and returns an
269    :class:`~django.http.HttpResponse` object with that rendered text.
270@@ -121,10 +124,14 @@ Optional arguments
271                                   my_data_dictionary,
272                                   context_instance=RequestContext(request))
273 
274-``mimetype``
275+``content_type``
276     The MIME type to use for the resulting document. Defaults to the value of
277     the :setting:`DEFAULT_CONTENT_TYPE` setting.
278 
279+    .. versionchanged:: 1.5
280+        This parameter used to be called ``mimetype``.
281+
282+
283 Example
284 -------
285 
286@@ -148,7 +155,7 @@ This example is equivalent to::
287         t = loader.get_template('myapp/template.html')
288         c = Context({'foo': 'bar'})
289         return HttpResponse(t.render(c),
290-            mimetype="application/xhtml+xml")
291+            content_type="application/xhtml+xml")
292 
293 ``redirect``
294 ============
295diff --git a/tests/regressiontests/views/generic_urls.py b/tests/regressiontests/views/generic_urls.py
296index 0f214d1..d504362 100644
297--- a/tests/regressiontests/views/generic_urls.py
298+++ b/tests/regressiontests/views/generic_urls.py
299@@ -47,7 +47,7 @@ urlpatterns += patterns('',
300 urlpatterns += patterns('regressiontests.views.views',
301     (r'^shortcuts/render_to_response/$', 'render_to_response_view'),
302     (r'^shortcuts/render_to_response/request_context/$', 'render_to_response_view_with_request_context'),
303-    (r'^shortcuts/render_to_response/mimetype/$', 'render_to_response_view_with_mimetype'),
304+    (r'^shortcuts/render_to_response/content_type/$', 'render_to_response_view_with_content_type'),
305     (r'^shortcuts/render/$', 'render_view'),
306     (r'^shortcuts/render/base_context/$', 'render_view_with_base_context'),
307     (r'^shortcuts/render/content_type/$', 'render_view_with_content_type'),
308diff --git a/tests/regressiontests/views/tests/shortcuts.py b/tests/regressiontests/views/tests/shortcuts.py
309index 62bd82f..3a5df6a 100644
310--- a/tests/regressiontests/views/tests/shortcuts.py
311+++ b/tests/regressiontests/views/tests/shortcuts.py
312@@ -21,8 +21,8 @@ class ShortcutTests(TestCase):
313         self.assertEqual(response.content, b'FOO.BAR../path/to/static/media/\n')
314         self.assertEqual(response['Content-Type'], 'text/html; charset=utf-8')
315 
316-    def test_render_to_response_with_mimetype(self):
317-        response = self.client.get('/shortcuts/render_to_response/mimetype/')
318+    def test_render_to_response_with_content_type(self):
319+        response = self.client.get('/shortcuts/render_to_response/content_type/')
320         self.assertEqual(response.status_code, 200)
321         self.assertEqual(response.content, b'FOO.BAR..\n')
322         self.assertEqual(response['Content-Type'], 'application/x-rendertest')
323diff --git a/tests/regressiontests/views/views.py b/tests/regressiontests/views/views.py
324index 748f076..50ad98a 100644
325--- a/tests/regressiontests/views/views.py
326+++ b/tests/regressiontests/views/views.py
327@@ -68,11 +68,11 @@ def render_to_response_view_with_request_context(request):
328         'bar': 'BAR',
329     }, context_instance=RequestContext(request))
330 
331-def render_to_response_view_with_mimetype(request):
332+def render_to_response_view_with_content_type(request):
333     return render_to_response('debug/render_test.html', {
334         'foo': 'FOO',
335         'bar': 'BAR',
336-    }, mimetype='application/x-rendertest')
337+    }, content_type='application/x-rendertest')
338 
339 def render_view(request):
340     return render(request, 'debug/render_test.html', {
341@@ -263,4 +263,4 @@ class Klass(object):
342             return technical_500_response(request, *exc_info)
343 
344 def sensitive_method_view(request):
345-    return Klass().method(request)
346\ No newline at end of file
347+    return Klass().method(request)