Ticket #10588: 0001-pass-render_to_response-status-param-through-to-Http.patch

File 0001-pass-render_to_response-status-param-through-to-Http.patch, 3.5 KB (added by Mike Lundy, 16 years ago)
  • django/shortcuts/__init__.py

    From 7b9cb41a091119d23a1226f1f612649b2d64709d Mon Sep 17 00:00:00 2001
    From: Mike Lundy <mike@fluffypenguin.org>
    Date: Sun, 22 Mar 2009 18:02:18 -0500
    Subject: [PATCH] pass render_to_response status param through to HttpResponse
    
    ---
     django/shortcuts/__init__.py                       |    2 +-
     .../regressiontests/test_client_regress/models.py  |    7 +++++++
     tests/regressiontests/test_client_regress/urls.py  |    1 +
     tests/regressiontests/test_client_regress/views.py |    4 ++++
     4 files changed, 13 insertions(+), 1 deletions(-)
    
    diff --git a/django/shortcuts/__init__.py b/django/shortcuts/__init__.py
    index 1cece7c..ffd30e8 100644
    a b def render_to_response(*args, **kwargs):  
    1414    Returns a HttpResponse whose content is filled with the result of calling
    1515    django.template.loader.render_to_string() with the passed arguments.
    1616    """
    17     httpresponse_kwargs = {'mimetype': kwargs.pop('mimetype', None)}
     17    httpresponse_kwargs = dict([(k, kwargs.pop(k, None)) for k in ('mimetype', 'status')])
    1818    return HttpResponse(loader.render_to_string(*args, **kwargs), **httpresponse_kwargs)
    1919
    2020def _get_queryset(klass):
  • tests/regressiontests/test_client_regress/models.py

    diff --git a/tests/regressiontests/test_client_regress/models.py b/tests/regressiontests/test_client_regress/models.py
    index 5d65092..d225bdd 100644
    a b class QueryStringTests(TestCase):  
    594594        self.assertEqual(response.context['post-bar'], 'bang')
    595595        self.assertEqual(response.context['request-foo'], 'whiz')
    596596        self.assertEqual(response.context['request-bar'], 'bang')
     597
     598    def test_get_error_requests(self):
     599        response = self.client.get("/test_client_regress/request_error/", data={'status': 200})
     600        self.assertEqual(response.status_code, 200)
     601
     602        response = self.client.get("/test_client_regress/request_error/", data={'status': 404})
     603        self.assertEqual(response.status_code, 404)
  • tests/regressiontests/test_client_regress/urls.py

    diff --git a/tests/regressiontests/test_client_regress/urls.py b/tests/regressiontests/test_client_regress/urls.py
    index 0f9082d..f68ed03 100644
    a b urlpatterns = patterns('',  
    88    (r'^get_view/$', views.get_view),
    99    (r'^request_data/$', views.request_data),
    1010    (r'^request_data_extended/$', views.request_data, {'template':'extended.html', 'data':'bacon'}),
     11    (r'^request_error/$', views.request_error),
    1112    url(r'^arg_view/(?P<name>.+)/$', views.view_with_argument, name='arg_view'),
    1213    (r'^login_protected_redirect_view/$', views.login_protected_redirect_view),
    1314    (r'^redirects/$', redirect_to, {'url': '/test_client_regress/redirects/further/'}),
  • tests/regressiontests/test_client_regress/views.py

    diff --git a/tests/regressiontests/test_client_regress/views.py b/tests/regressiontests/test_client_regress/views.py
    index bd0b8af..ede7029 100644
    a b def request_data(request, template='base.html', data='sausage'):  
    3131        'data': data,
    3232    })
    3333
     34def request_error(request, template='base.html'):
     35    "A simple view that returns the given status code"
     36    return render_to_response(template, {}, status=int(request.REQUEST.get('status', 200)))
     37
    3438def view_with_argument(request, name):
    3539    """A view that takes a string argument
    3640
Back to Top