Ticket #19692: 19692-2.diff

File 19692-2.diff, 15.5 KB (added by Aymeric Augustin, 11 years ago)
  • django/contrib/sitemaps/views.py

    diff --git a/django/contrib/sitemaps/views.py b/django/contrib/sitemaps/views.py
    index cfe3aa6..c8d2f4d 100644
    a b  
     1import warnings
     2
    13from django.contrib.sites.models import get_current_site
    24from django.core import urlresolvers
    35from django.core.paginator import EmptyPage, PageNotAnInteger
    from django.template.response import TemplateResponse  
    68from django.utils import six
    79
    810def index(request, sitemaps,
    9           template_name='sitemap_index.xml', mimetype='application/xml',
    10           sitemap_url_name='django.contrib.sitemaps.views.sitemap'):
     11          template_name='sitemap_index.xml', content_type='application/xml',
     12          sitemap_url_name='django.contrib.sitemaps.views.sitemap',
     13          mimetype=None):
     14
     15    if mimetype:
     16        warnings.warn("The mimetype keyword argument is deprecated, use "
     17            "content_type instead", DeprecationWarning, stacklevel=2)
     18        content_type = mimetype
     19
    1120    req_protocol = 'https' if request.is_secure() else 'http'
    1221    req_site = get_current_site(request)
    1322
    def index(request, sitemaps,  
    2433            sites.append('%s?p=%s' % (absolute_url, page))
    2534
    2635    return TemplateResponse(request, template_name, {'sitemaps': sites},
    27                             content_type=mimetype)
     36                            content_type=content_type)
    2837
    2938def sitemap(request, sitemaps, section=None,
    30             template_name='sitemap.xml', mimetype='application/xml'):
     39            template_name='sitemap.xml', content_type='application/xml',
     40            mimetype=None):
     41
     42    if mimetype:
     43        warnings.warn("The mimetype keyword argument is deprecated, use "
     44            "content_type instead", DeprecationWarning, stacklevel=2)
     45        content_type = mimetype
     46
    3147    req_protocol = 'https' if request.is_secure() else 'http'
    3248    req_site = get_current_site(request)
    3349
    def sitemap(request, sitemaps, section=None,  
    5167        except PageNotAnInteger:
    5268            raise Http404("No page '%s'" % page)
    5369    return TemplateResponse(request, template_name, {'urlset': urls},
    54                             content_type=mimetype)
     70                            content_type=content_type)
  • django/shortcuts/__init__.py

    diff --git a/django/shortcuts/__init__.py b/django/shortcuts/__init__.py
    index 9f89634..21bd7a0 100644
    a b This module collects helper functions and classes that "span" multiple levels  
    33of MVC. In other words, these functions/classes introduce controlled coupling
    44for convenience's sake.
    55"""
     6import warnings
    67
    78from django.template import loader, RequestContext
    89from django.http import HttpResponse, Http404
    def render_to_response(*args, **kwargs):  
    1718    Returns a HttpResponse whose content is filled with the result of calling
    1819    django.template.loader.render_to_string() with the passed arguments.
    1920    """
    20     httpresponse_kwargs = {'content_type': kwargs.pop('mimetype', None)}
     21    httpresponse_kwargs = {'content_type': kwargs.pop('content_type', None)}
     22
     23    mimetype = kwargs.pop('mimetype', None)
     24    if mimetype:
     25        warnings.warn("The mimetype keyword argument is deprecated, use "
     26            "content_type instead", DeprecationWarning, stacklevel=2)
     27        httpresponse_kwargs['content_type'] = mimetype
     28
    2129    return HttpResponse(loader.render_to_string(*args, **kwargs), **httpresponse_kwargs)
    2230
    2331def render(request, *args, **kwargs):
  • docs/howto/outputting-csv.txt

    diff --git a/docs/howto/outputting-csv.txt b/docs/howto/outputting-csv.txt
    index bcc6f38..1f9efb5 100644
    a b Here's an example::  
    2020
    2121    def some_view(request):
    2222        # Create the HttpResponse object with the appropriate CSV header.
    23         response = HttpResponse(mimetype='text/csv')
     23        response = HttpResponse(content_type='text/csv')
    2424        response['Content-Disposition'] = 'attachment; filename="somefilename.csv"'
    2525
    2626        writer = csv.writer(response)
    Here's an example, which generates the same CSV file as above::  
    9292
    9393    def some_view(request):
    9494        # Create the HttpResponse object with the appropriate CSV header.
    95         response = HttpResponse(mimetype='text/csv')
     95        response = HttpResponse(content_type='text/csv')
    9696        response['Content-Disposition'] = 'attachment; filename="somefilename.csv"'
    9797
    9898        # The data is hard-coded here, but you could load it from a database or
    Here's an example, which generates the same CSV file as above::  
    111111
    112112The only difference between this example and the previous example is that this
    113113one uses template loading instead of the CSV module. The rest of the code --
    114 such as the ``mimetype='text/csv'`` -- is the same.
     114such as the ``content_type='text/csv'`` -- is the same.
    115115
    116116Then, create the template ``my_template_name.txt``, with this template code:
    117117
  • docs/howto/outputting-pdf.txt

    diff --git a/docs/howto/outputting-pdf.txt b/docs/howto/outputting-pdf.txt
    index 9d87b97..d15f94f 100644
    a b Here's a "Hello World" example::  
    5151
    5252    def some_view(request):
    5353        # Create the HttpResponse object with the appropriate PDF headers.
    54         response = HttpResponse(mimetype='application/pdf')
     54        response = HttpResponse(content_type='application/pdf')
    5555        response['Content-Disposition'] = 'attachment; filename="somefilename.pdf"'
    5656
    5757        # Create the PDF object, using the response object as its "file."
    Here's the above "Hello World" example rewritten to use :mod:`io`::  
    120120
    121121    def some_view(request):
    122122        # Create the HttpResponse object with the appropriate PDF headers.
    123         response = HttpResponse(mimetype='application/pdf')
     123        response = HttpResponse(content_type='application/pdf')
    124124        response['Content-Disposition'] = 'attachment; filename="somefilename.pdf"'
    125125
    126126        buffer = BytesIO()
  • docs/internals/deprecation.txt

    diff --git a/docs/internals/deprecation.txt b/docs/internals/deprecation.txt
    index 63d65d1..da0d1e2 100644
    a b these changes.  
    290290  specified as a plain string instead of a tuple will be removed and raise an
    291291  exception.
    292292
    293 * The ``mimetype`` argument to :class:`~django.http.HttpResponse` ``__init__``
    294   will be removed (``content_type`` should be used instead).
     293* The ``mimetype`` argument to the ``__init__`` methods of
     294  :class:`~django.http.HttpResponse`,
     295  :class:`~django.template.response.SimpleTemplateResponse`, and
     296  :class:`~django.template.response.TemplateResponse`, will be removed.
     297  ``content_type`` should be used instead. This also applies to the
     298  :func:`~django.shortcuts.render_to_response` shortcut and
     299  the sitemamp views, :func:`~django.contrib.sitemaps.views.index` and
     300  :func:`~django.contrib.sitemaps.views.sitemap`.
    295301
    296302* When :class:`~django.http.HttpResponse` is instantiated with an iterator,
    297303  or when :attr:`~django.http.HttpResponse.content` is set to an iterator,
  • docs/ref/contrib/admin/actions.txt

    diff --git a/docs/ref/contrib/admin/actions.txt b/docs/ref/contrib/admin/actions.txt
    index d7eef62..0a302ec 100644
    a b objects as JSON::  
    223223    from django.core import serializers
    224224
    225225    def export_as_json(modeladmin, request, queryset):
    226         response = HttpResponse(mimetype="text/javascript")
     226        response = HttpResponse(content_type="application/json")
    227227        serializers.serialize("json", queryset, stream=response)
    228228        return response
    229229
    Conditionally enabling or disabling actions  
    356356                    if 'delete_selected' in actions:
    357357                        del actions['delete_selected']
    358358                return actions
    359 
    360 
  • docs/ref/template-response.txt

    diff --git a/docs/ref/template-response.txt b/docs/ref/template-response.txt
    index 3f5e772..844b5fa 100644
    a b Attributes  
    5656Methods
    5757-------
    5858
    59 .. method:: SimpleTemplateResponse.__init__(template, context=None, mimetype=None, status=None, content_type=None)
     59.. method:: SimpleTemplateResponse.__init__(template, context=None, content_type=None, status=None)
    6060
    6161    Instantiates a
    6262    :class:`~django.template.response.SimpleTemplateResponse` object
    63     with the given template, context, MIME type and HTTP status.
     63    with the given template, context, content type, and HTTP status.
    6464
    6565    ``template``
    6666        The full name of a template, or a sequence of template names.
    Methods  
    7575        The HTTP Status code for the response.
    7676
    7777    ``content_type``
    78         An alias for ``mimetype``. Historically, this parameter was only called
    79         ``mimetype``, but since this is actually the value included in the HTTP
    80         ``Content-Type`` header, it can also include the character set encoding,
    81         which makes it more than just a MIME type specification. If ``mimetype``
    82         is specified (not ``None``), that value is used. Otherwise,
    83         ``content_type`` is used. If neither is given,
     78
     79        .. versionchanged:: 1.5
     80
     81        Historically, this parameter was only called ``mimetype`` (now
     82        deprecated), but since this is actually the value included in the HTTP
     83        ``Content-Type`` header, it can also include the character set
     84        encoding, which makes it more than just a MIME type specification. If
     85        ``mimetype`` is specified (not ``None``), that value is used.
     86        Otherwise, ``content_type`` is used. If neither is given,
    8487        :setting:`DEFAULT_CONTENT_TYPE` is used.
    8588
    8689
    TemplateResponse objects  
    144147Methods
    145148-------
    146149
    147 .. method:: TemplateResponse.__init__(request, template, context=None, mimetype=None, status=None, content_type=None, current_app=None)
     150.. method:: TemplateResponse.__init__(request, template, context=None, content_type=None, status=None, current_app=None)
    148151
    149152    Instantiates an ``TemplateResponse`` object with the given
    150153    template, context, MIME type and HTTP status.
    Methods  
    165168        The HTTP Status code for the response.
    166169
    167170    ``content_type``
    168         An alias for ``mimetype``. Historically, this parameter was only called
    169         ``mimetype``, but since this is actually the value included in the HTTP
    170         ``Content-Type`` header, it can also include the character set encoding,
    171         which makes it more than just a MIME type specification. If ``mimetype``
    172         is specified (not ``None``), that value is used. Otherwise,
    173         ``content_type`` is used. If neither is given,
     171
     172        .. versionchanged:: 1.5
     173
     174        Historically, this parameter was only called ``mimetype`` (now
     175        deprecated), but since this is actually the value included in the HTTP
     176        ``Content-Type`` header, it can also include the character set
     177        encoding, which makes it more than just a MIME type specification. If
     178        ``mimetype`` is specified (not ``None``), that value is used.
     179        Otherwise, ``content_type`` is used. If neither is given,
    174180        :setting:`DEFAULT_CONTENT_TYPE` is used.
    175181
    176182    ``current_app``
  • docs/topics/http/shortcuts.txt

    diff --git a/docs/topics/http/shortcuts.txt b/docs/topics/http/shortcuts.txt
    index b1b4700..68860f1 100644
    a b Optional arguments  
    5050    The MIME type to use for the resulting document. Defaults to the value of
    5151    the :setting:`DEFAULT_CONTENT_TYPE` setting.
    5252
     53    .. versionchanged:: 1.5
     54        This parameter used to be called ``mimetype``.
     55
    5356``status``
    5457    The status code for the response. Defaults to ``200``.
    5558
    This example is equivalent to::  
    8790``render_to_response``
    8891======================
    8992
    90 .. function:: render_to_response(template_name[, dictionary][, context_instance][, mimetype])
     93.. function:: render_to_response(template_name[, dictionary][, context_instance][, content_type])
    9194
    9295   Renders a given template with a given context dictionary and returns an
    9396   :class:`~django.http.HttpResponse` object with that rendered text.
    Optional arguments  
    121124                                  my_data_dictionary,
    122125                                  context_instance=RequestContext(request))
    123126
    124 ``mimetype``
     127``content_type``
    125128    The MIME type to use for the resulting document. Defaults to the value of
    126129    the :setting:`DEFAULT_CONTENT_TYPE` setting.
    127130
     131    .. versionchanged:: 1.5
     132        This parameter used to be called ``mimetype``.
     133
     134
    128135Example
    129136-------
    130137
    This example is equivalent to::  
    148155        t = loader.get_template('myapp/template.html')
    149156        c = Context({'foo': 'bar'})
    150157        return HttpResponse(t.render(c),
    151             mimetype="application/xhtml+xml")
     158            content_type="application/xhtml+xml")
    152159
    153160``redirect``
    154161============
  • tests/regressiontests/views/generic_urls.py

    diff --git a/tests/regressiontests/views/generic_urls.py b/tests/regressiontests/views/generic_urls.py
    index 0f214d1..d504362 100644
    a b urlpatterns += patterns('',  
    4747urlpatterns += patterns('regressiontests.views.views',
    4848    (r'^shortcuts/render_to_response/$', 'render_to_response_view'),
    4949    (r'^shortcuts/render_to_response/request_context/$', 'render_to_response_view_with_request_context'),
    50     (r'^shortcuts/render_to_response/mimetype/$', 'render_to_response_view_with_mimetype'),
     50    (r'^shortcuts/render_to_response/content_type/$', 'render_to_response_view_with_content_type'),
    5151    (r'^shortcuts/render/$', 'render_view'),
    5252    (r'^shortcuts/render/base_context/$', 'render_view_with_base_context'),
    5353    (r'^shortcuts/render/content_type/$', 'render_view_with_content_type'),
  • tests/regressiontests/views/tests/shortcuts.py

    diff --git a/tests/regressiontests/views/tests/shortcuts.py b/tests/regressiontests/views/tests/shortcuts.py
    index 62bd82f..3a5df6a 100644
    a b class ShortcutTests(TestCase):  
    2121        self.assertEqual(response.content, b'FOO.BAR../path/to/static/media/\n')
    2222        self.assertEqual(response['Content-Type'], 'text/html; charset=utf-8')
    2323
    24     def test_render_to_response_with_mimetype(self):
    25         response = self.client.get('/shortcuts/render_to_response/mimetype/')
     24    def test_render_to_response_with_content_type(self):
     25        response = self.client.get('/shortcuts/render_to_response/content_type/')
    2626        self.assertEqual(response.status_code, 200)
    2727        self.assertEqual(response.content, b'FOO.BAR..\n')
    2828        self.assertEqual(response['Content-Type'], 'application/x-rendertest')
  • tests/regressiontests/views/views.py

    diff --git a/tests/regressiontests/views/views.py b/tests/regressiontests/views/views.py
    index 748f076..50ad98a 100644
    a b def render_to_response_view_with_request_context(request):  
    6868        'bar': 'BAR',
    6969    }, context_instance=RequestContext(request))
    7070
    71 def render_to_response_view_with_mimetype(request):
     71def render_to_response_view_with_content_type(request):
    7272    return render_to_response('debug/render_test.html', {
    7373        'foo': 'FOO',
    7474        'bar': 'BAR',
    75     }, mimetype='application/x-rendertest')
     75    }, content_type='application/x-rendertest')
    7676
    7777def render_view(request):
    7878    return render(request, 'debug/render_test.html', {
    class Klass(object):  
    263263            return technical_500_response(request, *exc_info)
    264264
    265265def sensitive_method_view(request):
    266     return Klass().method(request)
    267  No newline at end of file
     266    return Klass().method(request)
Back to Top