Skip to content

Commit

Permalink
provide django4 compatibility (#1) (#227)
Browse files Browse the repository at this point in the history
provide django4 compatibility
Co-authored-by: Frank DiRocco <[email protected]>
  • Loading branch information
arthanson authored Jun 5, 2022
1 parent 737d881 commit d40d3d5
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 47 deletions.
43 changes: 23 additions & 20 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,37 @@ services:
- postgresql

addons:
postgresql: "9.6"
# https://gis.stackexchange.com/a/252610
# apt:
# packages:
# - postgresql-9.6-postgis-2.3
postgresql: "10"
apt:
packages:
- postgresql-10-postgis-2.4

python:
- "3.6"
- "3.7"
- "3.8"
- "3.9"
- "3.10"

env:
- DJANGO_VERSION='Django>=1.11,<1.12'
global:
- PGPORT=5432
- PGUSER=postgres
jobs:
- DJANGO_VERSION='Django>=2.2,<2.3'
- DJANGO_VERSION='Django>=3.0,<3.1'
- DJANGO_VERSION='https://github.com/django/django/archive/master.tar.gz'

matrix:
allow_failures:
- python: "3.8"
env: DJANGO_VERSION='Django>=1.11,<1.12'
- env: DJANGO_VERSION='https://github.com/django/django/archive/master.tar.gz'

before_install:
# https://gis.stackexchange.com/a/252610
- wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
- sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt/ xenial-pgdg main" >> /etc/apt/sources.list.d/postgresql.list'
- sudo apt-get install --yes postgresql-9.6-postgis-2.4
- DJANGO_VERSION='Django>=3.1,<3.2'
- DJANGO_VERSION='Django>=3.2,<4.0'
- DJANGO_VERSION='Django>=4.0,<4.1'

jobs:
exclude:
- python: "3.6"
env: DJANGO_VERSION='Django>=4.0,<4.1'
- python: "3.7"
env: DJANGO_VERSION='Django>=4.0,<4.1'
- python: "3.10"
env: DJANGO_VERSION='Django>=2.2,<2.3'
env: DJANGO_VERSION='Django>=3.1,<3.2'

install:
- pip install $DJANGO_VERSION
Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ django-cities provides you with place related models (eg. Country, Region, City)

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

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

| Key | |
| :-------------------: | :------------------------------------------------------------------ |
Expand Down
5 changes: 4 additions & 1 deletion cities/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
import django
from django.conf import settings as django_settings
from django.core.exceptions import ImproperlyConfigured
from django.utils.translation import ugettext_lazy as _
if float('.'.join(map(str, django.VERSION[:2]))) < 3:
from django.utils.translation import ugettext_lazy as _
else:
from django.utils.translation import gettext_lazy as _

__all__ = [
'city_types', 'district_types',
Expand Down
15 changes: 10 additions & 5 deletions cities/models.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
from random import choice
from string import ascii_uppercase, digits

try:
from django.utils.encoding import force_unicode as force_text
except (NameError, ImportError):
from django.utils.encoding import force_text
from .conf import (ALTERNATIVE_NAME_TYPES, SLUGIFY_FUNCTION, DJANGO_VERSION)


if DJANGO_VERSION < 4:
try:
from django.utils.encoding import force_unicode as force_text
except (NameError, ImportError):
from django.utils.encoding import force_text
else:
from django.utils.encoding import force_str as force_text

from django.db import transaction
from django.contrib.gis.db.models import PointField
Expand All @@ -14,7 +20,6 @@
from model_utils import Choices
import swapper

from .conf import (ALTERNATIVE_NAME_TYPES, SLUGIFY_FUNCTION, DJANGO_VERSION)
from .managers import AlternativeNameManager
from .util import unicode_func

Expand Down
13 changes: 9 additions & 4 deletions cities/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,15 @@
import unicodedata
from math import radians, sin, cos, acos
from django import VERSION as DJANGO_VERSION
try:
from django.utils.encoding import force_unicode as force_text
except (NameError, ImportError):
from django.utils.encoding import force_text

if DJANGO_VERSION < (4, 0):
try:
from django.utils.encoding import force_unicode as force_text
except (NameError, ImportError):
from django.utils.encoding import force_text
else:
from django.utils.encoding import force_str as force_text

from django.utils.safestring import mark_safe, SafeText

from .conf import CONTINENT_DATA
Expand Down
6 changes: 5 additions & 1 deletion example/urls.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
from django import VERSION as DJANGO_VERSION
from django.conf.urls import include, url
try:
from django.conf.urls import url
except ImportError:
from django.urls import re_path as url
from django.conf.urls import include
from django.contrib import admin
from django.views.generic import ListView
from cities.models import (Country, Region, City, District, PostalCode)
Expand Down
7 changes: 5 additions & 2 deletions test_project/test_app/urls.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
from django.conf.urls import url
try:
from django.conf.urls import url
except ImportError:
from django.urls import re_path as url

from django.contrib import admin
from django.core.exceptions import ImproperlyConfigured

from cities.util import patterns


app_name = "test_app"

try:
Expand Down
17 changes: 9 additions & 8 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
[tox]
envlist =
py33-dj1.8,
py{27,34,35,36}-dj1.{8,9,10,11}
py{34,35,36}-dj2.0
{py36,py37,py38,py39}-django22,
{py36,py37,py38,py39}-django31,
{py36,py37,py38,py39,py310}-django32,
{py38,py39,py310}-django40,

[testenv]
commands=python {toxinidir}/test_project/manage.py test {posargs:test_app} --noinput
passenv = DJANGO_VERSION POSTGRES_USER POSTGRES_PASSWORD TRAVIS_BRANCH
TRAVIS_COMMIT TRAVIS_LOG_LEVEL TRAVIS_PULL_REQUEST_BRANCH
TRAVIS_REPO_SLUG

deps =
dj1.8: Django ~=1.8.0
dj1.9: Django ~=1.9.0
dj1.10: Django ~=1.10.0
dj1.11: Django ~=1.11.0
dj2.0: Django ~=2.0.0
django22: Django>=2.2,<3.0
django31: Django>=3.1,<3.2
django32: Django>=3.2,<4.0
django40: Django>=4.0,<5.0

psycopg2

0 comments on commit d40d3d5

Please sign in to comment.