Skip to content

Commit 529e449

Browse files
authored
[change] Dropped support for Django 3.2 and lower
- Remove compatibility for Django < 4.2 - Modernize the code for Django 4.2 with the help of django-upgrade https://github.com/adamchainz/django-upgrade
1 parent 141ac90 commit 529e449

File tree

9 files changed

+28
-122
lines changed

9 files changed

+28
-122
lines changed

.github/workflows/ci.yml

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -29,28 +29,10 @@ jobs:
2929
fail-fast: false
3030
matrix:
3131
env:
32-
- python: '3.8'
33-
TOXENV: py38-django32-djangorestframework312
34-
- python: '3.8'
35-
TOXENV: py38-django32-djangorestframework313
36-
- python: '3.8'
37-
TOXENV: py38-django32-djangorestframework314
3832
- python: '3.8'
3933
TOXENV: py38-django42-djangorestframework314
40-
- python: '3.9'
41-
TOXENV: py39-django32-djangorestframework312
42-
- python: '3.9'
43-
TOXENV: py39-django32-djangorestframework313
44-
- python: '3.9'
45-
TOXENV: py39-django32-djangorestframework314
4634
- python: '3.9'
4735
TOXENV: py39-django42-djangorestframework314
48-
- python: '3.10'
49-
TOXENV: py310-django32-djangorestframework312
50-
- python: '3.10'
51-
TOXENV: py310-django32-djangorestframework313
52-
- python: '3.10'
53-
TOXENV: py310-django32-djangorestframework314
5436
- python: '3.10'
5537
TOXENV: py310-django42-djangorestframework314
5638
- python: '3.11'

README.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,7 @@ at latitudes > 60 degrees are > 25%.
602602
DistanceToPointOrderingFilter
603603
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
604604

605-
Provides a ``DistanceToPointOrderingFilter``, **available on Django >= 3.0**, which is a subclass of ``DistanceToPointFilter``.
605+
Provides a ``DistanceToPointOrderingFilter``, which is a subclass of ``DistanceToPointFilter``.
606606
Orders a queryset by distance to a given point, from the nearest to the most distant point.
607607

608608
``views.py:``
@@ -692,11 +692,11 @@ The recommended way to run the tests is by using
692692
`pip install tox`.
693693

694694
You can use ``tox -l`` to list the available environments, and then e.g. use
695-
the following to run all tests with Python 3.6 and Django 1.11:
695+
the following to run all tests with Python 3.8 and Django 4.2:
696696

697697
.. code-block:: bash
698698
699-
tox -e py36-django111
699+
tox -e py38-django42
700700
701701
By default Django's test runner is used, but there is a variation of tox's
702702
envlist to use pytest (using the ``-pytest`` suffix).
@@ -705,7 +705,7 @@ You can pass optional arguments to the test runner like this:
705705

706706
.. code-block:: bash
707707
708-
tox -e py36-django111-pytest -- -k test_foo
708+
tox -e py38-django42-pytest -- -k test_foo
709709
710710
Running tests manually
711711
======================

rest_framework_gis/__init__.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,3 @@ def get_version():
1212
if VERSION[3] != 'final':
1313
version = '%s %s' % (version, VERSION[3])
1414
return version
15-
16-
17-
try:
18-
import django
19-
20-
if django.VERSION < (3, 2):
21-
default_app_config = 'rest_framework_gis.apps.AppConfig'
22-
except ImportError:
23-
pass

rest_framework_gis/filters.py

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
from django.contrib.gis import forms
44
from django.contrib.gis.db import models
5+
from django.contrib.gis.db.models.fields import BaseSpatialField
6+
from django.contrib.gis.db.models.functions import GeometryDistance
57
from django.contrib.gis.geos import Point, Polygon
68
from django.core.exceptions import ImproperlyConfigured
79
from django.db.models import Q
@@ -17,24 +19,8 @@
1719
'restframework-gis filters depend on package "django-filter" '
1820
'which is missing. Install with "pip install django-filter".'
1921
)
20-
try:
21-
# Django >= 2.0
22-
from django.contrib.gis.db.models.fields import BaseSpatialField
23-
except ImportError:
24-
try: # pragma: no cover
25-
# django >= 1.8,<2.0
26-
from django.contrib.gis.db.models.lookups import gis_lookups
27-
except ImportError: # pragma: no cover
28-
# django <= 1.7
29-
gis_lookups = models.sql.query.ALL_TERMS
30-
else:
31-
gis_lookups = BaseSpatialField.get_lookups()
3222

33-
try:
34-
# Django >= 3.0
35-
from django.contrib.gis.db.models.functions import GeometryDistance
36-
except ImportError:
37-
GeometryDistance = None
23+
gis_lookups = BaseSpatialField.get_lookups()
3824

3925

4026
__all__ = [
@@ -273,9 +259,6 @@ class DistanceToPointOrderingFilter(DistanceToPointFilter):
273259
order_param = 'order'
274260

275261
def filter_queryset(self, request, queryset, view):
276-
if not GeometryDistance:
277-
raise ValueError('GeometryDistance not available on this version of django')
278-
279262
filter_field = getattr(view, 'distance_ordering_filter_field', None)
280263

281264
if not filter_field:

tests/django_restframework_gis_tests/admin.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
from .models import Location
55

66

7+
@admin.register(Location)
78
class LocationAdmin(GeoModelAdmin):
89
list_display = ('name', 'geometry')
9-
10-
11-
admin.site.register(Location, LocationAdmin)

tests/django_restframework_gis_tests/test_bbox.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
11
import json
22

3-
from django.test import TestCase
4-
5-
try:
6-
from django.urls import reverse
7-
except ImportError:
8-
from django.core.urlresolvers import reverse
9-
103
from django.core.exceptions import ImproperlyConfigured
4+
from django.test import TestCase
5+
from django.urls import reverse
116

127
from rest_framework_gis import serializers as gis_serializers
138

tests/django_restframework_gis_tests/test_filters.py

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,10 @@
33
from unittest import skipIf
44

55
from django.conf import settings
6+
from django.contrib.gis.db.models.functions import GeometryDistance
67
from django.contrib.gis.geos import GEOSGeometry, Polygon
78
from django.test import TestCase
8-
9-
try:
10-
from django.urls import reverse
11-
except ImportError:
12-
from django.core.urlresolvers import reverse
9+
from django.urls import reverse
1310

1411
from .models import Location
1512
from .views import (
@@ -23,13 +20,6 @@
2320
== 'django.contrib.gis.db.backends.spatialite'
2421
)
2522

26-
try:
27-
from django.contrib.gis.db.models.functions import GeometryDistance
28-
29-
has_geometry_distance = GeometryDistance and True
30-
except ImportError:
31-
has_geometry_distance = False
32-
3323

3424
class TestRestFrameworkGisFilters(TestCase):
3525
"""
@@ -349,10 +339,6 @@ def test_DistanceToPointFilter_filtering(self):
349339
has_spatialite,
350340
'Skipped test for spatialite backend: missing feature "GeometryDistance"',
351341
)
352-
@skipIf(
353-
not has_geometry_distance,
354-
'Skipped test for Django < 3.0: missing feature "GeometryDistance"',
355-
)
356342
def test_DistanceToPointOrderingFilter_filtering(self):
357343
"""
358344
Checks that the DistanceOrderingFilter returns the objects in the correct order
@@ -563,10 +549,6 @@ def test_DistanceToPointFilter_ValueError_distance(self):
563549
'Invalid distance string supplied for parameter dist',
564550
)
565551

566-
@skipIf(
567-
not has_geometry_distance,
568-
'Skipped test for Django < 3.0: missing feature "GeometryDistance"',
569-
)
570552
def test_DistanceToPointOrderingFilter_filtering_none(self):
571553
url_params = '?point=&format=json'
572554
response = self.client.get(
@@ -576,10 +558,6 @@ def test_DistanceToPointOrderingFilter_filtering_none(self):
576558
response.data, {'type': 'FeatureCollection', 'features': []}
577559
)
578560

579-
@skipIf(
580-
not has_geometry_distance,
581-
'Skipped test for Django < 3.0: missing feature "GeometryDistance"',
582-
)
583561
def test_DistanceToPointOrderingFilter_ordering_filter_field_none(self):
584562
original_value = (
585563
GeojsonLocationOrderDistanceToPointList.distance_ordering_filter_field
@@ -595,11 +573,3 @@ def test_DistanceToPointOrderingFilter_ordering_filter_field_none(self):
595573
GeojsonLocationOrderDistanceToPointList.distance_ordering_filter_field = (
596574
original_value
597575
)
598-
599-
@skipIf(has_geometry_distance, 'Skipped test for Django >= 3.0')
600-
def test_DistanceToPointOrderingFilter_not_available(self):
601-
url_params = '?point=12,42&format=json'
602-
with self.assertRaises(ValueError):
603-
self.client.get(
604-
'%s%s' % (self.location_order_distance_to_point, url_params)
605-
)

tests/django_restframework_gis_tests/tests.py

Lines changed: 16 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,11 @@
88
from unittest import skipIf
99

1010
import django
11-
from django.contrib.gis.geos import GEOSGeometry, Point
12-
from django.test import TestCase
13-
14-
try:
15-
from django.urls import reverse
16-
except ImportError:
17-
from django.core.urlresolvers import reverse
18-
1911
import rest_framework
12+
from django.contrib.gis.geos import GEOSGeometry, Point
2013
from django.core.exceptions import ImproperlyConfigured
14+
from django.test import TestCase
15+
from django.urls import reverse
2116

2217
from rest_framework_gis import serializers as gis_serializers
2318
from rest_framework_gis.fields import GeoJsonDict
@@ -40,16 +35,10 @@ def setUp(self):
4035
'Unable to convert to python object:'
4136
' Invalid geometry pointer returned from "OGR_G_CreateGeometryFromJson".'
4237
)
43-
if django.VERSION >= (2, 0, 0):
44-
self.value_error_message = (
45-
"Unable to convert to python object:"
46-
" String input unrecognized as WKT EWKT, and HEXEWKB."
47-
)
48-
else:
49-
self.value_error_message = (
50-
"Unable to convert to python object:"
51-
" String or unicode input unrecognized as WKT EWKT, and HEXEWKB."
52-
)
38+
self.value_error_message = (
39+
"Unable to convert to python object:"
40+
" String input unrecognized as WKT EWKT, and HEXEWKB."
41+
)
5342
self.type_error_message = (
5443
"Unable to convert to python object: Improper geometry input type:"
5544
)
@@ -144,7 +133,7 @@ def test_post_HTML_browsable_api(self):
144133
),
145134
}
146135
response = self.client.post(
147-
self.location_list_url, data, HTTP_ACCEPT='text/html'
136+
self.location_list_url, data, headers={"accept": 'text/html'}
148137
)
149138
self.assertEqual(response.status_code, 201)
150139
self.assertEqual(Location.objects.count(), 1)
@@ -300,7 +289,7 @@ def test_geojson_format(self):
300289
self.assertCountEqual(json.dumps(response.data), json.dumps(expected))
301290
else:
302291
self.assertItemsEqual(json.dumps(response.data), json.dumps(expected))
303-
response = self.client.get(url, HTTP_ACCEPT='text/html')
292+
response = self.client.get(url, headers={"accept": 'text/html'})
304293
self.assertContains(response, "Kool geojson test")
305294

306295
def test_geojson_id_attribute(self):
@@ -402,7 +391,7 @@ def test_post_geojson_location_list_HTML(self):
402391
self.geojson_location_list_url,
403392
data=json.dumps(data),
404393
content_type='application/json',
405-
HTTP_ACCEPT='text/html',
394+
headers={"accept": 'text/html'},
406395
)
407396
self.assertEqual(response.status_code, 201)
408397
self.assertEqual(Location.objects.count(), 1)
@@ -506,12 +495,12 @@ def test_geofeatured_model_post_as_multipartformdata(self):
506495

507496
def test_HTML_browsable_geojson_location_list(self):
508497
response = self.client.get(
509-
self.geojson_location_list_url, HTTP_ACCEPT='text/html'
498+
self.geojson_location_list_url, headers={"accept": 'text/html'}
510499
)
511500
self.assertEqual(response.status_code, 200)
512501
self._create_locations()
513502
response = self.client.get(
514-
self.geojson_location_list_url, HTTP_ACCEPT='text/html'
503+
self.geojson_location_list_url, headers={"accept": 'text/html'}
515504
)
516505
self.assertContains(response, 'l1')
517506
self.assertContains(response, 'l2')
@@ -523,7 +512,7 @@ def test_post_geojson_location_list_HTML_web_form(self):
523512
"geometry": json.dumps({"type": "Point", "coordinates": [10.1, 10.1]}),
524513
}
525514
response = self.client.post(
526-
self.geojson_location_list_url, data, HTTP_ACCEPT='text/html'
515+
self.geojson_location_list_url, data, headers={"accept": 'text/html'}
527516
)
528517
self.assertEqual(response.status_code, 201)
529518
self.assertEqual(Location.objects.count(), 1)
@@ -535,7 +524,7 @@ def test_post_geojson_location_list_HTML_web_form_WKT(self):
535524
self.assertEqual(Location.objects.count(), 0)
536525
data = {"name": "HTML test WKT", "geometry": "POINT (10.1 10.1)"}
537526
response = self.client.post(
538-
self.geojson_location_list_url, data, HTTP_ACCEPT='text/html'
527+
self.geojson_location_list_url, data, headers={"accept": 'text/html'}
539528
)
540529
self.assertEqual(response.status_code, 201)
541530
self.assertEqual(Location.objects.count(), 1)
@@ -546,7 +535,7 @@ def test_post_geojson_location_list_HTML_web_form_WKT(self):
546535
def test_geojson_HTML_widget_value(self):
547536
self._create_locations()
548537
response = self.client.get(
549-
self.geojson_location_list_url, HTTP_ACCEPT='text/html'
538+
self.geojson_location_list_url, headers={"accept": 'text/html'}
550539
)
551540
self.assertContains(response, '<textarea name="geometry"')
552541
self.assertContains(response, '"type": "Point"')
@@ -556,7 +545,7 @@ def test_geojson_HTML_widget_value(self):
556545
def test_geojson_HTML_widget_value_pre_drf_39(self):
557546
self._create_locations()
558547
response = self.client.get(
559-
self.geojson_location_list_url, HTTP_ACCEPT='text/html'
548+
self.geojson_location_list_url, headers={"accept": 'text/html'}
560549
)
561550
self.assertContains(response, '<textarea name="geometry"')
562551
self.assertContains(response, '&quot;type&quot;: &quot;Point&quot;')

tox.ini

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
[tox]
22
envlist =
3-
py{38,39,310}-django{32}-djangorestframework{312,313,314}{,-pytest}
43
py{38,39,310}-django{42,50}-djangorestframework{314}{,-pytest}
54
py{311}-django{42}-djangorestframework{314}{,-pytest}
65
py{311,312}-django{50}-djangorestframework{315}{,-pytest}
@@ -18,7 +17,6 @@ commands =
1817
coverage run {env:DRFG_TEST_RUNNER} {posargs:tests/django_restframework_gis_tests} --parallel
1918

2019
deps =
21-
django32: Django~=3.2.0
2220
django42: Django~=4.2.0
2321
django50: Django~=5.0.0
2422
django51: Django~=5.1.0

0 commit comments

Comments
 (0)