Skip to content

Commit 39a8382

Browse files
Add Django 4.0 support (#387)
* force_text was removed in favor of force_str * ugettext_lazy was removed in favor of gettext_lazy * added Python 3.9 and 3.10 to the test matrix, because they're supported by Django 4.0 (while excluding Django versions, which do not support 3.9 and 3.10)
1 parent c0612d6 commit 39a8382

File tree

8 files changed

+64
-9
lines changed

8 files changed

+64
-9
lines changed

.github/workflows/ci.yml

+30-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ jobs:
1313
fail-fast: false
1414

1515
matrix:
16-
python-version: ["2.7", "3.6", "3.7", "3.8"]
17-
django-version: ["1.11", "2.0", "2.2", "2.1", "3.0", "3.1","3.2"]
16+
python-version: ["2.7", "3.6", "3.7", "3.8", "3.9", "3.10"]
17+
django-version: ["1.11", "2.0", "2.2", "2.1", "3.0", "3.1","3.2", "4.0"]
1818
es-dsl-version: ["6.4", "7.4"]
1919
es-version: ["7.13.4"]
2020

@@ -31,6 +31,14 @@ jobs:
3131
django-version: "3.1"
3232
- python-version: "2.7"
3333
django-version: "3.2"
34+
- python-version: "2.7"
35+
django-version: "4.0"
36+
37+
- python-version: "3.6"
38+
django-version: "4.0"
39+
40+
- python-version: "3.7"
41+
django-version: "4.0"
3442

3543
- python-version: "3.8"
3644
django-version: "1.11"
@@ -39,6 +47,26 @@ jobs:
3947
- python-version: "3.8"
4048
django-version: "2.1"
4149

50+
- python-version: "3.9"
51+
django-version: "1.11"
52+
- python-version: "3.9"
53+
django-version: "2.0"
54+
- python-version: "3.9"
55+
django-version: "2.1"
56+
57+
- python-version: "3.10"
58+
django-version: "1.11"
59+
- python-version: "3.10"
60+
django-version: "2.0"
61+
- python-version: "3.10"
62+
django-version: "2.1"
63+
- python-version: "3.10"
64+
django-version: "2.2"
65+
- python-version: "3.10"
66+
django-version: "3.0"
67+
- python-version: "3.10"
68+
django-version: "3.1"
69+
4270
steps:
4371
- name: Install and Run Elasticsearch
4472
uses: elastic/elastic-github-actions/elasticsearch@master

django_elasticsearch_dsl/fields.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
from types import MethodType
22

3+
import django
34
from django.core.exceptions import ObjectDoesNotExist
45
from django.db import models
56
from django.db.models.fields.files import FieldFile
6-
from django.utils.encoding import force_text
7+
if django.VERSION < (4, 0):
8+
from django.utils.encoding import force_text as force_str
9+
else:
10+
from django.utils.encoding import force_str
711
from django.utils.functional import Promise
812
from elasticsearch_dsl.field import (
913
Boolean,
@@ -86,7 +90,7 @@ def get_value_from_instance(self, instance, field_value_to_ignore=None):
8690

8791
# convert lazy object like lazy translations to string
8892
if isinstance(instance, Promise):
89-
return force_text(instance)
93+
return force_str(instance)
9094

9195
return instance
9296

setup.py

+3
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
'Framework :: Django :: 3.0',
5959
'Framework :: Django :: 3.1',
6060
'Framework :: Django :: 3.2',
61+
'Framework :: Django :: 4.0',
6162
'Intended Audience :: Developers',
6263
'License :: OSI Approved :: BSD License',
6364
'Natural Language :: English',
@@ -68,5 +69,7 @@
6869
'Programming Language :: Python :: 3.6',
6970
'Programming Language :: Python :: 3.7',
7071
'Programming Language :: Python :: 3.8',
72+
'Programming Language :: Python :: 3.9',
73+
'Programming Language :: Python :: 3.10',
7174
],
7275
)

tests/models.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
# -*- coding: utf-8 -*-
22
from __future__ import unicode_literals
3+
4+
import django
35
from django.db import models
4-
from django.utils.translation import ugettext_lazy as _
6+
if django.VERSION < (4, 0):
7+
from django.utils.translation import ugettext_lazy as _
8+
else:
9+
from django.utils.translation import gettext_lazy as _
510
from six import python_2_unicode_compatible
611

712

tests/test_documents.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
import json
22
from unittest import TestCase
33

4+
import django
45
from django.db import models
5-
from django.utils.translation import ugettext_lazy as _
6+
if django.VERSION < (4, 0):
7+
from django.utils.translation import ugettext_lazy as _
8+
else:
9+
from django.utils.translation import gettext_lazy as _
610
from elasticsearch_dsl import GeoPoint, InnerDoc
711
from mock import patch, Mock
812

tests/test_fields.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
from unittest import TestCase
22

3+
import django
34
from django.db.models.fields.files import FieldFile
4-
from django.utils.translation import ugettext_lazy as _
5+
if django.VERSION < (4, 0):
6+
from django.utils.translation import ugettext_lazy as _
7+
else:
8+
from django.utils.translation import gettext_lazy as _
59
from mock import Mock, NonCallableMock
610
from six import string_types
711

tests/test_integration.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
from datetime import datetime
22
import unittest
33

4+
import django
45
from django.core.management import call_command
56
from django.test import TestCase
6-
from django.utils.translation import ugettext_lazy as _
7+
if django.VERSION < (4, 0):
8+
from django.utils.translation import ugettext_lazy as _
9+
else:
10+
from django.utils.translation import gettext_lazy as _
711
from six import StringIO
812

913
from elasticsearch.exceptions import NotFoundError

tox.ini

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[tox]
22
envlist =
33
py27-django-111-es74
4-
{py36,py37,py38}-django-{111,20,21,22,30,31,32}-{es64,es74}
4+
{py36,py37,py38,py39,py310}-django-{111,20,21,22,30,31,32,40}-{es64,es74}
55

66
[testenv]
77
setenv =
@@ -16,6 +16,7 @@ deps =
1616
django-30: Django>=3.0,<3.1
1717
django-31: Django>=3.1,<3.2
1818
django-32: Django>=3.2,<3.3
19+
django-40: Django>=4.0,<4.1
1920
es64: elasticsearch-dsl>=6.4.0,<7.0.0
2021
es74: elasticsearch-dsl>=7.4.0,<8
2122
-r{toxinidir}/requirements_test.txt
@@ -25,3 +26,5 @@ basepython =
2526
py36: python3.6
2627
py37: python3.7
2728
py38: python3.8
29+
py39: python3.9
30+
py310: python3.10

0 commit comments

Comments
 (0)