Skip to content

Commit

Permalink
Prepare for Django 4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
morlandi committed Dec 27, 2021
1 parent 702d2ac commit 93d777d
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 7 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
History
=======

...
v4.4.0
------
* Prepare for Django 4.0
* Support choice lookup for m2m_foreign_field (many thanks to Martin Schwier and Etienne Pouliot)
* Fix Multiple search values when you set search_values_separator = '+' and try to search for term with + in it (many thanks to Petr Dlouhý)
* POSSIBLE INCOMPATIBLE CHANGE: for security reason, HTML tags are now stripped by default in the rendered table; you can disable this setting AJAX_DATATABLE_STRIP_HTML_TAGS = False (thus restoring the previous behaviour); many thanks to Mich "Mike3285"
Expand Down
2 changes: 1 addition & 1 deletion ajax_datatable/columns.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import datetime
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _
from django.db import models
from .exceptions import ColumnOrderError
from .utils import format_datetime
Expand Down
19 changes: 16 additions & 3 deletions ajax_datatable/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from django.http import JsonResponse
from django.template import TemplateDoesNotExist
from django.template import loader
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _

from .columns import Column
from .columns import ColumnLink
Expand Down Expand Up @@ -364,7 +364,14 @@ def dispatch(self, request, *args, **kwargs):
request.REQUEST = request.GET if request.method == 'GET' else request.POST

self.initialize(request)
if request.is_ajax():

try:
is_ajax_request = request.accepts("application/json")
except AttributeError as e:
# Django < 4.0
is_ajax_request = request.is_ajax()

if is_ajax_request:
action = request.REQUEST.get('action', '')
if action == 'initialize':

Expand Down Expand Up @@ -514,7 +521,13 @@ def get(self, request, *args, **kwargs):

t0 = datetime.datetime.now()

if not request.is_ajax():
try:
is_ajax_request = request.accepts("application/json")
except AttributeError as e:
# Django < 4.0
is_ajax_request = request.is_ajax()

if not is_ajax_request:
return HttpResponseBadRequest()

try:
Expand Down
2 changes: 1 addition & 1 deletion example/backend/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from django.urls import reverse
from django.utils import timezone
from django.conf import settings
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _
from django.core.exceptions import PermissionDenied
from ajax_datatable.utils import format_datetime

Expand Down
2 changes: 1 addition & 1 deletion example/frontend/ajax_datatable_views.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django.contrib.auth import get_user_model
from ajax_datatable.views import AjaxDatatableView
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _
from django.contrib.auth.models import Permission

from project.query_debugger import query_debugger
Expand Down

0 comments on commit 93d777d

Please sign in to comment.