From dd1c3d7be88e9fd23f68b36393a370b184decdc8 Mon Sep 17 00:00:00 2001 From: kromem Date: Sat, 26 Jan 2013 21:49:52 -0500 Subject: [PATCH] Added radiosilence commit and wrote test --- djpjax.py | 11 +++++++---- tests.py | 9 +++++++++ 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/djpjax.py b/djpjax.py index 6cc559c..403efa9 100644 --- a/djpjax.py +++ b/djpjax.py @@ -29,10 +29,13 @@ def _view(request, *args, **kwargs): # if not hasattr(resp, "is_rendered"): # warnings.warn("@pjax used with non-template-response view") # return resp - if request.META.get('HTTP_X_PJAX', False): - resp.context_data[context_var] = pjax_parent - elif parent: - resp.context_data[context_var] = parent + try: + if request.META.get('HTTP_X_PJAX', False): + resp.context_data[context_var] = pjax_parent + elif parent: + resp.context_data[context_var] = parent + except AttributeError: + pass return resp return _view return pjaxtend_decorator diff --git a/tests.py b/tests.py index 6487ad0..73d9fa3 100644 --- a/tests.py +++ b/tests.py @@ -3,6 +3,7 @@ import djpjax from django.template.response import TemplateResponse +from django.http import HttpResponse from django.test.client import RequestFactory from django.views.generic import View @@ -89,6 +90,10 @@ def test_pjaxtend_custom_context(): resp = view_custom_context_pjaxtend(pjax_request) assert resp.template_name == "template.html" assert resp.context_data['my_parent'] == "parent-pjax.html" + +def test_handle_httpresponse(): + resp = view_httpresponse(regular_request) + assert resp.status_code == 200 # The test "views" themselves. @@ -124,6 +129,10 @@ def view_custom_parent_pjaxtend(request): def view_custom_context_pjaxtend(request): return TemplateResponse(request, "template.html", {}) +@djpjax.pjaxtend() +def view_httpresponse(request): + return HttpResponse("This is a test.") + class NoPJAXTemplateVew(djpjax.PJAXResponseMixin, View): template_name = 'template.html'