Skip to content
This repository has been archived by the owner on Nov 25, 2017. It is now read-only.

Fix for pjaxtend with HttpResponse w/ test #11

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions djpjax.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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.

Expand Down Expand Up @@ -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'

Expand Down