Skip to content

Commit

Permalink
Fix warning on Django 3.1 (#110)
Browse files Browse the repository at this point in the history
* Fix warning on Django 3.1

* Add Django 3.1 to the travis definition.

* Drop Python 2 and Django <2.2
  • Loading branch information
adamchainz authored Oct 27, 2020
1 parent f8b32cd commit 1761635
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 62 deletions.
25 changes: 7 additions & 18 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ sudo: required
language: python

python:
- 3.4
- 3.5
- 3.6
- 3.7
Expand All @@ -23,10 +22,9 @@ addons:
- libsqlite3-mod-spatialite

env:
- DJANGO_VERSION=2.0.13
- DJANGO_VERSION=2.1.15
- DJANGO_VERSION=2.2.10
- DJANGO_VERSION=3.0.3
- DJANGO_VERSION=2.2.16
- DJANGO_VERSION=3.0.10
- DJANGO_VERSION=3.1.2

install:
# This is a dependency of our Django test script
Expand All @@ -40,23 +38,14 @@ before_script:
- flake8 --ignore=E501,W504 djgeojson

script:
- coverage run quicktest.py djgeojson
- python -W error::DeprecationWarning -W error::PendingDeprecationWarning -W ignore:::site -W ignore:::distutils -m coverage run quicktest.py djgeojson

after_success:
- coveralls

matrix:
exclude:
- python: 3.4
env: DJANGO_VERSION=2.1.15
- python: 3.4
env: DJANGO_VERSION=2.2.10
- python: 3.4
env: DJANGO_VERSION=3.0.3
- python: 3.5
env: DJANGO_VERSION=3.0.3
- python: 3.8
env: DJANGO_VERSION=2.0.13
- python: 3.8
env: DJANGO_VERSION=2.1.15

env: DJANGO_VERSION=3.0.10
- python: 3.5
env: DJANGO_VERSION=3.1.2
3 changes: 2 additions & 1 deletion djgeojson/fields.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from __future__ import unicode_literals

from django.forms.widgets import HiddenInput
from django.utils.translation import ugettext_lazy as _
from django.core.exceptions import (ValidationError,
ImproperlyConfigured)
from django.utils.translation import gettext_lazy as _

try:
from leaflet.forms.widgets import LeafletWidget
HAS_LEAFLET = True
Expand Down
23 changes: 9 additions & 14 deletions djgeojson/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,12 @@
Itself, adapted from @jeffkistler's geojson serializer at: https://gist.github.com/967274
"""
try:
from cStringIO import StringIO
except ImportError:
from six import StringIO # NOQA
import json
import logging
from io import StringIO # NOQA

from contextlib import contextmanager

from six import string_types, iteritems

import django
from django.db.models.base import Model

Expand All @@ -31,7 +26,7 @@
Deserializer as PythonDeserializer)
from django.core.serializers.json import DjangoJSONEncoder
from django.core.serializers.base import SerializationError, DeserializationError
from django.utils.encoding import smart_text
from django.utils.encoding import smart_str
from django.core.exceptions import ImproperlyConfigured

try:
Expand Down Expand Up @@ -196,7 +191,7 @@ def start_object(self, obj):
primary_key = None
if self.primary_key and hasattr(self.primary_key, '__call__'):
primary_key = self.primary_key(obj)
elif self.primary_key and isinstance(self.primary_key, string_types):
elif self.primary_key and isinstance(self.primary_key, str):
if isinstance(obj, Model):
primary_key = getattr(obj, self.primary_key)
else:
Expand Down Expand Up @@ -224,7 +219,7 @@ def end_object(self, obj):
# Add extra-info for deserializing
with_modelname = self.options.get('with_modelname', True)
if hasattr(obj, '_meta') and with_modelname:
self._current['properties']['model'] = smart_text(obj._meta)
self._current['properties']['model'] = smart_str(obj._meta)

# If geometry not in model fields, may be a dynamic attribute
if 'geometry' not in self._current:
Expand Down Expand Up @@ -334,7 +329,7 @@ def handle_fk_field(self, obj, field):
related = related._get_pk_val()
else:
# Related to remote object via other field
related = smart_text(getattr(related, get_field_remote_field(field).field_name), strings_only=True)
related = smart_str(getattr(related, get_field_remote_field(field).field_name), strings_only=True)
self._current['properties'][field.name] = related

def handle_m2m_field(self, obj, field):
Expand All @@ -349,7 +344,7 @@ def m2m_value(value):
return value.natural_key()
else:
def m2m_value(value):
return smart_text(value._get_pk_val(), strings_only=True)
return smart_str(value._get_pk_val(), strings_only=True)
self._current['properties'][field.name] = [m2m_value(related)
for related in getattr(obj, field.name).iterator()]

Expand All @@ -359,7 +354,7 @@ def reverse_value(value):
return value.natural_key()
else:
def reverse_value(value):
return smart_text(value._get_pk_val(), strings_only=True)
return smart_str(value._get_pk_val(), strings_only=True)
values = [reverse_value(related) for related in getattr(obj, field_name).iterator()]
self._current['properties'][field_name] = values

Expand Down Expand Up @@ -491,7 +486,7 @@ def FeatureToPython(dictobj):
model = _get_model(model_name)
field_names = [f.name for f in model._meta.fields]
fields = {}
for k, v in iteritems(properties):
for k, v in properties.items():
if k in field_names:
fields[k] = v
obj = {
Expand All @@ -506,7 +501,7 @@ def FeatureToPython(dictobj):
obj['fields'][geometry_field] = shape.wkt
return obj

if isinstance(stream_or_string, string_types):
if isinstance(stream_or_string, str):
stream = StringIO(stream_or_string)
else:
stream = stream_or_string
Expand Down
4 changes: 1 addition & 3 deletions djgeojson/templatetags/geojson_tags.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import json
import re

from six import string_types

from django import template
from django.core.exceptions import ImproperlyConfigured

Expand Down Expand Up @@ -36,7 +34,7 @@ def geojsonfeature(source, params=''):
properties = parse.get('properties', '').split(',')
srid = parse.get('srid') or GEOJSON_DEFAULT_SRID

if source is None or isinstance(source, string_types):
if source is None or isinstance(source, str):
return 'null'

if isinstance(source, (GEOSGeometry, GeometryField)):
Expand Down
22 changes: 11 additions & 11 deletions djgeojson/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from django.core.exceptions import ValidationError, SuspiciousOperation
from django.contrib.gis.db import models
from django.contrib.gis.geos import LineString, Point, GeometryCollection
from django.utils.encoding import smart_text
from django.utils.encoding import smart_str

from .templatetags.geojson_tags import geojsonfeature
from .serializers import Serializer
Expand Down Expand Up @@ -485,7 +485,7 @@ def test_view_default_options(self):
view = GeoJSONLayerView(model=Route)
view.object_list = []
response = view.render_to_response(context={})
geojson = json.loads(smart_text(response.content))
geojson = json.loads(smart_str(response.content))
self.assertEqual(geojson['features'][0]['geometry']['coordinates'],
[[0.0, 0.0], [1.0, 1.0]])

Expand All @@ -495,7 +495,7 @@ class FullGeoJSON(GeoJSONLayerView):
view = FullGeoJSON(model=Route)
view.object_list = []
response = view.render_to_response(context={})
geojson = json.loads(smart_text(response.content))
geojson = json.loads(smart_str(response.content))
self.assertEqual(geojson['features'][0]['properties']['name'],
'green')

Expand All @@ -505,7 +505,7 @@ class FullGeoJSON(GeoJSONLayerView):
view = FullGeoJSON(model=Sign)
view.object_list = []
response = view.render_to_response(context={})
geojson = json.loads(smart_text(response.content))
geojson = json.loads(smart_str(response.content))
self.assertEqual(geojson['features'][0]['properties']['route'],
1)

Expand All @@ -516,7 +516,7 @@ class FullGeoJSON(GeoJSONLayerView):
view = FullGeoJSON(model=Sign)
view.object_list = []
response = view.render_to_response(context={})
geojson = json.loads(smart_text(response.content))
geojson = json.loads(smart_str(response.content))
self.assertEqual(geojson['features'][0]['properties']['route'],
'green')

Expand Down Expand Up @@ -549,7 +549,7 @@ def test_view_with_kwargs(self):
'x': 8,
'y': 7}
response = self.view.render_to_response(context={})
geojson = json.loads(smart_text(response.content))
geojson = json.loads(smart_str(response.content))
self.assertEqual(geojson['features'][0]['geometry']['coordinates'], [[0.0, 1.0], [10.0, 1.0]])

def test_view_with_kwargs_wrong_type_z(self):
Expand Down Expand Up @@ -600,29 +600,29 @@ def test_view_with_kwargs_no_y(self):
def test_view_is_serialized_as_geojson(self):
self.view.args = [4, 8, 7]
response = self.view.render_to_response(context={})
geojson = json.loads(smart_text(response.content))
geojson = json.loads(smart_str(response.content))
self.assertEqual(geojson['features'][0]['geometry']['coordinates'],
[[0.0, 1.0], [10.0, 1.0]])

def test_view_trims_to_geometries_boundaries(self):
self.view.args = [8, 128, 127]
response = self.view.render_to_response(context={})
geojson = json.loads(smart_text(response.content))
geojson = json.loads(smart_str(response.content))
self.assertEqual(geojson['features'][0]['geometry']['coordinates'],
[[0.0, 1.0], [1.40625, 1.0]])

def test_geometries_trim_can_be_disabled(self):
self.view.args = [8, 128, 127]
self.view.trim_to_boundary = False
response = self.view.render_to_response(context={})
geojson = json.loads(smart_text(response.content))
geojson = json.loads(smart_str(response.content))
self.assertEqual(geojson['features'][0]['geometry']['coordinates'],
[[0.0, 1.0], [10.0, 1.0]])

def test_tile_extent_is_provided_in_collection(self):
self.view.args = [8, 128, 127]
response = self.view.render_to_response(context={})
geojson = json.loads(smart_text(response.content))
geojson = json.loads(smart_str(response.content))
self.assertEqual(geojson['bbox'],
[0.0, 0.0, 1.40625, 1.4061088354351565])

Expand Down Expand Up @@ -676,7 +676,7 @@ def setUp(self):
def test_within_viewport(self):
self.view.args = [12, 2125, 1338]
response = self.view.render_to_response(context={})
geojson = json.loads(smart_text(response.content))
geojson = json.loads(smart_str(response.content))
self.assertEqual(len(geojson['features']), 2)
self.assertEqual(geojson['features'][0]['geometry']['coordinates'],
[6.843322039261242, 52.76181518632031])
Expand Down
13 changes: 7 additions & 6 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@
open(os.path.join(here, 'CHANGES'), encoding='utf-8').read(),
license='LPGL, see LICENSE file.',
install_requires=[
'Django',
'six',
'Django>=2.2',
],
extras_require={
'field': ['jsonfield', 'django-leaflet>=0.12'],
'docs': ['sphinx', 'sphinx-autobuild'],
},
packages=find_packages(),
python_requires=">=3.5",
include_package_data=True,
zip_safe=False,
classifiers=['Topic :: Utilities',
Expand All @@ -33,8 +33,9 @@
'Environment :: Web Environment',
'Framework :: Django',
'Development Status :: 5 - Production/Stable',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3.3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5'],
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
],
)
18 changes: 9 additions & 9 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@
# and then run "tox" from this directory.

[tox]
envlist = py27, py33, py34, py35, py36
envlist =
py35-django{22}
py36-django{22,30,31}
py37-django{22,30,31}
py38-django{22,30,31}

[testenv]
commands = python quicktest.py djgeojson
deps =
six
jsonfield

[testenv:py27]
commands = python -W error::DeprecationWarning -W error::PendingDeprecationWarning -W ignore:::site -W ignore:::distutils quicktest.py djgeojson
deps =
django22: django>=2.2,<3.0
django30: django>=3.0,<3.1
django31: django>=3.1,<3.2
six
jsonfield
django<2.0
git+git://github.com/tinio/pysqlite.git@extension-enabled#egg=pysqlite

0 comments on commit 1761635

Please sign in to comment.