Skip to content

Commit d40d3d5

Browse files
arthansonfdr2
andauthored
provide django4 compatibility (#1) (#227)
provide django4 compatibility Co-authored-by: Frank DiRocco <[email protected]>
1 parent 737d881 commit d40d3d5

File tree

8 files changed

+71
-47
lines changed

8 files changed

+71
-47
lines changed

.travis.yml

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,34 +6,37 @@ services:
66
- postgresql
77

88
addons:
9-
postgresql: "9.6"
10-
# https://gis.stackexchange.com/a/252610
11-
# apt:
12-
# packages:
13-
# - postgresql-9.6-postgis-2.3
9+
postgresql: "10"
10+
apt:
11+
packages:
12+
- postgresql-10-postgis-2.4
1413

1514
python:
1615
- "3.6"
1716
- "3.7"
1817
- "3.8"
18+
- "3.9"
19+
- "3.10"
1920

2021
env:
21-
- DJANGO_VERSION='Django>=1.11,<1.12'
22+
global:
23+
- PGPORT=5432
24+
- PGUSER=postgres
25+
jobs:
2226
- DJANGO_VERSION='Django>=2.2,<2.3'
23-
- DJANGO_VERSION='Django>=3.0,<3.1'
24-
- DJANGO_VERSION='https://github.com/django/django/archive/master.tar.gz'
25-
26-
matrix:
27-
allow_failures:
28-
- python: "3.8"
29-
env: DJANGO_VERSION='Django>=1.11,<1.12'
30-
- env: DJANGO_VERSION='https://github.com/django/django/archive/master.tar.gz'
31-
32-
before_install:
33-
# https://gis.stackexchange.com/a/252610
34-
- wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
35-
- sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt/ xenial-pgdg main" >> /etc/apt/sources.list.d/postgresql.list'
36-
- sudo apt-get install --yes postgresql-9.6-postgis-2.4
27+
- DJANGO_VERSION='Django>=3.1,<3.2'
28+
- DJANGO_VERSION='Django>=3.2,<4.0'
29+
- DJANGO_VERSION='Django>=4.0,<4.1'
30+
31+
jobs:
32+
exclude:
33+
- python: "3.6"
34+
env: DJANGO_VERSION='Django>=4.0,<4.1'
35+
- python: "3.7"
36+
env: DJANGO_VERSION='Django>=4.0,<4.1'
37+
- python: "3.10"
38+
env: DJANGO_VERSION='Django>=2.2,<2.3'
39+
env: DJANGO_VERSION='Django>=3.1,<3.2'
3740

3841
install:
3942
- pip install $DJANGO_VERSION

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ django-cities provides you with place related models (eg. Country, Region, City)
1010

1111
This package officially supports all currently supported versions of Python/Django:
1212

13-
| Python | 3.6 | 3.7 | 3.8 |
14-
| :------------ | ------------------- | --------------------- | --------------------- |
15-
| Django 1.11 | :white_check_mark: | :white_check_mark: | :large_blue_circle: |
16-
| Django 2.2 | :white_check_mark: | :white_check_mark: | :white_check_mark: |
17-
| Django 3.0 | :white_check_mark: | :white_check_mark: | :white_check_mark: |
18-
| Django [master](https://github.com/django/django/archive/master.tar.gz) | :large_blue_circle: | :large_blue_circle: | :large_blue_circle: |
13+
| Python | 3.6 | 3.7 | 3.8 | 3.9 | 3.10 |
14+
| :------------ | ------------------- | --------------------- | --------------------- | --------------------- | --------------------- |
15+
| Django 2.2 | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :x: |
16+
| Django 3.1 | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :x: |
17+
| Django 3.2 | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: |
18+
| Django 4.0 | :x: | :x: | :white_check_mark: | :white_check_mark: | :white_check_mark: |
1919

2020
| Key | |
2121
| :-------------------: | :------------------------------------------------------------------ |

cities/conf.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@
66
import django
77
from django.conf import settings as django_settings
88
from django.core.exceptions import ImproperlyConfigured
9-
from django.utils.translation import ugettext_lazy as _
9+
if float('.'.join(map(str, django.VERSION[:2]))) < 3:
10+
from django.utils.translation import ugettext_lazy as _
11+
else:
12+
from django.utils.translation import gettext_lazy as _
1013

1114
__all__ = [
1215
'city_types', 'district_types',

cities/models.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
from random import choice
22
from string import ascii_uppercase, digits
33

4-
try:
5-
from django.utils.encoding import force_unicode as force_text
6-
except (NameError, ImportError):
7-
from django.utils.encoding import force_text
4+
from .conf import (ALTERNATIVE_NAME_TYPES, SLUGIFY_FUNCTION, DJANGO_VERSION)
5+
6+
7+
if DJANGO_VERSION < 4:
8+
try:
9+
from django.utils.encoding import force_unicode as force_text
10+
except (NameError, ImportError):
11+
from django.utils.encoding import force_text
12+
else:
13+
from django.utils.encoding import force_str as force_text
814

915
from django.db import transaction
1016
from django.contrib.gis.db.models import PointField
@@ -14,7 +20,6 @@
1420
from model_utils import Choices
1521
import swapper
1622

17-
from .conf import (ALTERNATIVE_NAME_TYPES, SLUGIFY_FUNCTION, DJANGO_VERSION)
1823
from .managers import AlternativeNameManager
1924
from .util import unicode_func
2025

cities/util.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,15 @@
44
import unicodedata
55
from math import radians, sin, cos, acos
66
from django import VERSION as DJANGO_VERSION
7-
try:
8-
from django.utils.encoding import force_unicode as force_text
9-
except (NameError, ImportError):
10-
from django.utils.encoding import force_text
7+
8+
if DJANGO_VERSION < (4, 0):
9+
try:
10+
from django.utils.encoding import force_unicode as force_text
11+
except (NameError, ImportError):
12+
from django.utils.encoding import force_text
13+
else:
14+
from django.utils.encoding import force_str as force_text
15+
1116
from django.utils.safestring import mark_safe, SafeText
1217

1318
from .conf import CONTINENT_DATA

example/urls.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
from django import VERSION as DJANGO_VERSION
2-
from django.conf.urls import include, url
2+
try:
3+
from django.conf.urls import url
4+
except ImportError:
5+
from django.urls import re_path as url
6+
from django.conf.urls import include
37
from django.contrib import admin
48
from django.views.generic import ListView
59
from cities.models import (Country, Region, City, District, PostalCode)

test_project/test_app/urls.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1-
from django.conf.urls import url
1+
try:
2+
from django.conf.urls import url
3+
except ImportError:
4+
from django.urls import re_path as url
5+
26
from django.contrib import admin
37
from django.core.exceptions import ImproperlyConfigured
48

59
from cities.util import patterns
610

7-
811
app_name = "test_app"
912

1013
try:

tox.ini

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
[tox]
22
envlist =
3-
py33-dj1.8,
4-
py{27,34,35,36}-dj1.{8,9,10,11}
5-
py{34,35,36}-dj2.0
3+
{py36,py37,py38,py39}-django22,
4+
{py36,py37,py38,py39}-django31,
5+
{py36,py37,py38,py39,py310}-django32,
6+
{py38,py39,py310}-django40,
67

78
[testenv]
89
commands=python {toxinidir}/test_project/manage.py test {posargs:test_app} --noinput
910
passenv = DJANGO_VERSION POSTGRES_USER POSTGRES_PASSWORD TRAVIS_BRANCH
1011
TRAVIS_COMMIT TRAVIS_LOG_LEVEL TRAVIS_PULL_REQUEST_BRANCH
1112
TRAVIS_REPO_SLUG
13+
1214
deps =
13-
dj1.8: Django ~=1.8.0
14-
dj1.9: Django ~=1.9.0
15-
dj1.10: Django ~=1.10.0
16-
dj1.11: Django ~=1.11.0
17-
dj2.0: Django ~=2.0.0
15+
django22: Django>=2.2,<3.0
16+
django31: Django>=3.1,<3.2
17+
django32: Django>=3.2,<4.0
18+
django40: Django>=4.0,<5.0
1819

1920
psycopg2

0 commit comments

Comments
 (0)