Skip to content

Commit 9c19530

Browse files
committed
Testing django 4
1 parent dd2afc1 commit 9c19530

File tree

5 files changed

+40
-14
lines changed

5 files changed

+40
-14
lines changed

.travis.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,23 @@
11
language: python
22

33
python:
4-
- 3.5
54
- 3.6
6-
- 3.7
75
- 3.8
6+
- 3.9
87

98
env:
109
- DJANGO_VERSION=2.*
1110
- DJANGO_VERSION=3.*
11+
- DJANGO_VERSION=4.*
1212

1313
matrix:
1414
exclude:
15-
- python: 3.5
16-
env: DJANGO_VERSION=3.*
15+
- python: 3.6
16+
env: DJANGO_VERSION=4.*
1717
- python: 3.8
1818
env: DJANGO_VERSION=2.*
19+
- python: 3.9
20+
env: DJANGO_VERSION=2.*
1921

2022
install:
2123
- pip install django==$DJANGO_VERSION

django_ajax/decorators.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,10 @@ def my_view(request):
5858
def decorator(func):
5959
@wraps(func, assigned=WRAPPER_ASSIGNMENTS)
6060
def inner(request, *args, **kwargs):
61-
if mandatory and not request.is_ajax():
61+
if mandatory and not request.headers.get('x-requested-with') == 'XMLHttpRequest':
6262
return HttpResponseBadRequest()
6363

64-
if request.is_ajax():
64+
if request.headers.get('x-requested-with') == 'XMLHttpRequest':
6565
# return json response
6666
try:
6767
return render_to_json(func(request, *args, **kwargs), request, **ajax_kwargs)

django_ajax/middleware.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def process_response(self, request, response):
1717
If the request was made by AJAX then convert response to JSON,
1818
otherwise return the original response.
1919
"""
20-
if request.is_ajax():
20+
if request.headers.get('x-requested-with') == 'XMLHttpRequest':
2121
return render_to_json(response)
2222
return response
2323

@@ -26,5 +26,5 @@ def process_exception(self, request, exception):
2626
Catch exception if the request was made by AJAX,
2727
after will become up on JSON.
2828
"""
29-
if request.is_ajax():
29+
if request.headers.get('x-requested-with') == 'XMLHttpRequest':
3030
return exception

tests/ajaxdecorator/urls.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,12 @@
33
import django
44

55
try:
6-
from django.conf.urls import patterns, include, url
6+
try:
7+
from django.conf.urls import patterns, include, url
8+
except ImportError:
9+
from django.conf.urls import include, url
710
except ImportError:
8-
from django.conf.urls import include, url
11+
from django.urls import include, re_path
912

1013
if django.VERSION < (1, 8):
1114
urlpatterns = patterns('',
@@ -16,7 +19,7 @@
1619
url(r'^ajax/exception$', views.exception_view, name='exception'),
1720
url(r'^ajax/raise-exception$', views.raise_exception_view, name='raise_exception'),
1821
)
19-
else:
22+
elif django.VERSION < (4, 0):
2023
urlpatterns = [
2124
url(r'^ajax/foo$', views.foo_view, name='foo'),
2225
url(r'^ajax/login-required$', views.login_required_view, name='login_required'),
@@ -25,3 +28,12 @@
2528
url(r'^ajax/exception$', views.exception_view, name='exception'),
2629
url(r'^ajax/raise-exception$', views.raise_exception_view, name='raise_exception'),
2730
]
31+
else:
32+
urlpatterns = [
33+
re_path(r'^ajax/foo$', views.foo_view, name='foo'),
34+
re_path(r'^ajax/login-required$', views.login_required_view, name='login_required'),
35+
re_path(r'^ajax/render$', views.render_view, name='render'),
36+
re_path(r'^ajax/render-class-based-view$', views.SimpleView.as_view(), name='render_class_based_view'),
37+
re_path(r'^ajax/exception$', views.exception_view, name='exception'),
38+
re_path(r'^ajax/raise-exception$', views.raise_exception_view, name='raise_exception'),
39+
]

tests/ajaxmiddleware/urls.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,12 @@
33
import django
44

55
try:
6-
from django.conf.urls import patterns, include, url
6+
try:
7+
from django.conf.urls import patterns, include, url
8+
except ImportError:
9+
from django.conf.urls import include, url
710
except ImportError:
8-
from django.conf.urls import include, url
11+
from django.urls import include, re_path
912

1013
if django.VERSION < (1, 8):
1114
urlpatterns = patterns('',
@@ -16,7 +19,7 @@
1619
url(r'^ajax/exception$', views.exception_view, name='exception'),
1720
url(r'^ajax/raise-exception$', views.raise_exception_view, name='raise_exception'),
1821
)
19-
else:
22+
elif django.VERSION < (4, 0):
2023
urlpatterns = [
2124
url(r'^ajax/foo$', views.foo_view, name='foo'),
2225
url(r'^ajax/login-required$', views.login_required_view, name='login_required'),
@@ -25,3 +28,12 @@
2528
url(r'^ajax/exception$', views.exception_view, name='exception'),
2629
url(r'^ajax/raise-exception$', views.raise_exception_view, name='raise_exception'),
2730
]
31+
else:
32+
urlpatterns = [
33+
re_path(r'^ajax/foo$', views.foo_view, name='foo'),
34+
re_path(r'^ajax/login-required$', views.login_required_view, name='login_required'),
35+
re_path(r'^ajax/render$', views.render_view, name='render'),
36+
re_path(r'^ajax/render-class-based-view$', views.SimpleView.as_view(), name='render_class_based_view'),
37+
re_path(r'^ajax/exception$', views.exception_view, name='exception'),
38+
re_path(r'^ajax/raise-exception$', views.raise_exception_view, name='raise_exception'),
39+
]

0 commit comments

Comments
 (0)