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

Commit 09b9347

Browse files
committed
- Changed template var from 'extend' to 'parent'
- README wrapped to 80 chars - Added tests for pjaxtend usage
1 parent de2faee commit 09b9347

File tree

3 files changed

+37
-8
lines changed

3 files changed

+37
-8
lines changed

README.rst

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,9 @@ That's it!
7878
Using Template Extensions
7979
-------------------------
8080

81-
If the content in your ``template-pjax.html`` file is very similar to your ``template.html`` an alternative method of operation is to use the decorator ``pjaxtend``, as follows::
81+
If the content in your ``template-pjax.html`` file is very similar to your
82+
``template.html`` an alternative method of operation is to use the decorator
83+
``pjaxtend``, as follows::
8284

8385
from djpjax import pjaxtend
8486
@@ -88,13 +90,15 @@ If the content in your ``template-pjax.html`` file is very similar to your ``tem
8890

8991
Then, in your ``template.html`` file you can do the following::
9092

91-
{% extends extend %}
93+
{% extends parent %}
9294
...
9395
...
9496

95-
Note that the template will extend ``someapp/base.html`` unless its a pjax request in which case it will extend ``pjax.html``.
97+
Note that the template will extend ``someapp/base.html`` unless its a pjax request
98+
in which case it will extend ``pjax.html``.
9699

97-
If you want to define which template to extend for a pjax request you can do so as follows::
100+
If you want to define which template to extend for a pjax request you can do so
101+
as follows::
98102
99103
from djpjax import pjaxtend
100104

djpjax.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def _view(request, *args, **kwargs):
2020
return _view
2121
return pjax_decorator
2222

23-
def pjaxtend(extend, pjax_extend='pjax.html'):
23+
def pjaxtend(parent, pjax_parent='pjax.html'):
2424
def pjaxtend_decorator(view):
2525
@functools.wraps(view)
2626
def _view(request, *args, **kwargs):
@@ -30,9 +30,9 @@ def _view(request, *args, **kwargs):
3030
# warnings.warn("@pjax used with non-template-response view")
3131
# return resp
3232
if request.META.get('HTTP_X_PJAX', False):
33-
resp.context_data['extend'] = pjax_extend
34-
elif extend:
35-
resp.context_data['extend'] = extend
33+
resp.context_data['parent'] = pjax_parent
34+
elif parent:
35+
resp.context_data['parent'] = parent
3636
return resp
3737
return _view
3838
return pjaxtend_decorator

tests.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,23 @@ def test_class_with_pjax_template():
5858
resp = view(pjax_request)
5959
assert resp.template_name[0] == "pjax.html"
6060

61+
def test_pjaxtend_default_parent():
62+
resp = view_default_parent_pjaxtend(regular_request)
63+
assert resp.template_name == "template.html"
64+
assert resp.context_data['parent'] == "parent.html"
65+
resp = view_default_parent_pjaxtend(pjax_request)
66+
assert resp.template_name == "template.html"
67+
assert resp.context_data['parent'] == "pjax.html"
68+
69+
def test_pjaxtend_custom_parent():
70+
resp = view_custom_parent_pjaxtend(regular_request)
71+
assert resp.template_name == "template.html"
72+
assert resp.context_data['parent'] == "parent.html"
73+
resp = view_custom_parent_pjaxtend(pjax_request)
74+
assert resp.template_name == "template.html"
75+
assert resp.context_data['parent'] == "parent-pjax.html"
76+
77+
6178
# The test "views" themselves.
6279

6380
@djpjax.pjax()
@@ -76,6 +93,14 @@ def view_with_pjax_template(request):
7693
def view_with_template_tuple(request):
7794
return TemplateResponse(request, ("template.html", "other_template.html"), {})
7895

96+
@djpjax.pjaxtend('parent.html')
97+
def view_default_parent_pjaxtend(request):
98+
return TemplateResponse(request, "template.html", {})
99+
100+
@djpjax.pjaxtend('parent.html', 'parent-pjax.html')
101+
def view_custom_parent_pjaxtend(request):
102+
return TemplateResponse(request, "template.html", {})
103+
79104
class NoPJAXTemplateVew(djpjax.PJAXResponseMixin, View):
80105
template_name = 'template.html'
81106

0 commit comments

Comments
 (0)