[Python-modules-commits] [djangorestframework-gis] 01/10: New upstream version 0.12

Michael Fladischer fladi at moszumanska.debian.org
Fri Nov 24 09:55:18 UTC 2017


This is an automated email from the git hooks/post-receive script.

fladi pushed a commit to branch debian/master
in repository djangorestframework-gis.

commit c53cd8c3051d7d80b9e38289a447d69922f1fbe4
Author: Michael Fladischer <FladischerMichael at fladi.at>
Date:   Fri Nov 24 10:20:17 2017 +0100

    New upstream version 0.12
---
 CHANGES.rst                                        | 11 ++++
 PKG-INFO                                           |  2 +-
 README.rst                                         |  7 +--
 djangorestframework_gis.egg-info/PKG-INFO          |  2 +-
 djangorestframework_gis.egg-info/requires.txt      |  3 +-
 requirements.txt                                   |  3 +-
 rest_framework_gis/__init__.py                     |  2 +-
 rest_framework_gis/fields.py                       | 27 ++++++----
 rest_framework_gis/filters.py                      | 19 ++++---
 setup.cfg                                          |  4 +-
 tests/django_restframework_gis_tests/models.py     |  1 -
 tests/django_restframework_gis_tests/test_bbox.py  |  5 +-
 .../django_restframework_gis_tests/test_filters.py |  5 +-
 .../test_performance.py                            |  6 ++-
 tests/django_restframework_gis_tests/tests.py      | 61 +++++++++++++++++++++-
 tests/django_restframework_gis_tests/views.py      |  2 +-
 tests/urls.py                                      |  7 ++-
 17 files changed, 131 insertions(+), 36 deletions(-)

diff --git a/CHANGES.rst b/CHANGES.rst
index 9517527..79b420f 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -1,6 +1,17 @@
 Changelog
 =========
 
+Version 0.12.0 [2017-11-12]
+---------------------------
+
+- `#138 <https://github.com/djangonauts/django-rest-framework-gis/pull/138>`_:
+  added support for ``GeometryCollection`` fields
+- `#146 <https://github.com/djangonauts/django-rest-framework-gis/pull/146>`_:
+  added compatibility with django-rest-framework 3.7
+- `#147 <https://github.com/djangonauts/django-rest-framework-gis/pull/147>`_:
+  added support to django 2.0 beta
+- dropped support for django 1.7, 1.8, 1.9 and 1.10
+
 Version 0.11.2 [2017-05-22]
 ---------------------------
 
diff --git a/PKG-INFO b/PKG-INFO
index 499a111..3a805be 100644
--- a/PKG-INFO
+++ b/PKG-INFO
@@ -1,6 +1,6 @@
 Metadata-Version: 1.1
 Name: djangorestframework-gis
-Version: 0.11.2
+Version: 0.12
 Summary: Geographic add-ons for Django Rest Framework
 Home-page: https://github.com/djangonauts/django-rest-framework-gis
 Author: Douglas Meehan
diff --git a/README.rst b/README.rst
index 71010cd..5c640c3 100644
--- a/README.rst
+++ b/README.rst
@@ -39,6 +39,7 @@ Compatibility with DRF, Django and Python
 
 ===============  ============================ ==================== ==================================
 DRF-gis version  DRF version                  Django version       Python version
+**0.12.x**       **3.1** to **3.7**           **1.11** to **2.0**   **2.7** to **3.6**
 **0.11.x**       **3.1** to **3.6**           **1.7** to **1.11**  **2.7** to **3.6**
 **0.10.x**       **3.1** to **3.3**           **1.7** to **1.9**   **2.7** to **3.5**
 **0.9.6**        **3.1** to **3.2**           **1.5** to **1.8**   **2.6** to **3.5**
@@ -304,7 +305,7 @@ read access for a REST client and can be achieved using ``auto_bbox``. Example:
             auto_bbox = True
 
 
-The second approach uses the ``bbox_geo_field`` to specify an addional
+The second approach uses the ``bbox_geo_field`` to specify an additional
 ``GeometryField`` of the model which will be used to calculate the bounding box. This allows
 boundingboxes differ from the exact extent of a features geometry. Additionally this
 enables read and write access for the REST client. Bounding boxes send from the client will
@@ -485,8 +486,8 @@ a certain bounding box.
         filter_backends = (InBBoxFilter, )
         bbox_filter_include_overlapping = True # Optional
 
-We can then filter in the URL, using Bounding Box format (min Lat, min
-Lon, max Lat, max Lon), and we can search for instances within the
+We can then filter in the URL, using Bounding Box format (min Lon, min
+Lat, max Lon, max Lat), and we can search for instances within the
 bounding box, e.g.:
 ``/location/?in_bbox=-90,29,-89,35``.
 
diff --git a/djangorestframework_gis.egg-info/PKG-INFO b/djangorestframework_gis.egg-info/PKG-INFO
index 499a111..3a805be 100644
--- a/djangorestframework_gis.egg-info/PKG-INFO
+++ b/djangorestframework_gis.egg-info/PKG-INFO
@@ -1,6 +1,6 @@
 Metadata-Version: 1.1
 Name: djangorestframework-gis
-Version: 0.11.2
+Version: 0.12
 Summary: Geographic add-ons for Django Rest Framework
 Home-page: https://github.com/djangonauts/django-rest-framework-gis
 Author: Douglas Meehan
diff --git a/djangorestframework_gis.egg-info/requires.txt b/djangorestframework_gis.egg-info/requires.txt
index 455ac6f..d04748e 100644
--- a/djangorestframework_gis.egg-info/requires.txt
+++ b/djangorestframework_gis.egg-info/requires.txt
@@ -1 +1,2 @@
-djangorestframework>=3.3,<3.7
+six
+djangorestframework>=3.3,<3.8
diff --git a/requirements.txt b/requirements.txt
index 455ac6f..d04748e 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -1 +1,2 @@
-djangorestframework>=3.3,<3.7
+six
+djangorestframework>=3.3,<3.8
diff --git a/rest_framework_gis/__init__.py b/rest_framework_gis/__init__.py
index 8040329..ab48b61 100644
--- a/rest_framework_gis/__init__.py
+++ b/rest_framework_gis/__init__.py
@@ -1,4 +1,4 @@
-VERSION = (0, 11, 2, 'final')
+VERSION = (0, 12, 0, 'final')
 __version__ = VERSION  # alias
 
 
diff --git a/rest_framework_gis/fields.py b/rest_framework_gis/fields.py
index a6a872e..407bae2 100644
--- a/rest_framework_gis/fields.py
+++ b/rest_framework_gis/fields.py
@@ -1,8 +1,9 @@
+import six  # TODO Remove this along with GeoJsonDict when support for python 2.6/2.7 is dropped.
 import json
 from collections import OrderedDict
 
 from django.contrib.gis.geos import GEOSGeometry, GEOSException
-from django.contrib.gis.gdal import OGRException
+from django.contrib.gis.gdal import GDALException
 from django.core.exceptions import ValidationError
 from django.utils.translation import ugettext_lazy as _
 from rest_framework.fields import Field, SerializerMethodField
@@ -25,10 +26,7 @@ class GeometryField(Field):
         if isinstance(value, dict) or value is None:
             return value
         # we expect value to be a GEOSGeometry instance
-        return GeoJsonDict((
-            ('type', value.geom_type),
-            ('coordinates', value.coords),
-        ))
+        return GeoJsonDict(value.geojson)
 
     def to_internal_value(self, value):
         if value == '' or value is None:
@@ -40,7 +38,7 @@ class GeometryField(Field):
             value = json.dumps(value)
         try:
             return GEOSGeometry(value)
-        except (ValueError, GEOSException, OGRException, TypeError):
+        except (ValueError, GEOSException, GDALException, TypeError):
             raise ValidationError(_('Invalid format: string or unicode input unrecognized as GeoJSON, WKT EWKT or HEXEWKB.'))
 
     def validate_empty_values(self, data):
@@ -54,10 +52,7 @@ class GeometrySerializerMethodField(SerializerMethodField):
         value = super(GeometrySerializerMethodField, self).to_representation(value)
         if value is not None:
             # we expect value to be a GEOSGeometry instance
-            return GeoJsonDict((
-                ('type', value.geom_type),
-                ('coordinates', value.coords),
-            ))
+            return GeoJsonDict(value.geojson)
         else:
             return None
 
@@ -67,6 +62,18 @@ class GeoJsonDict(OrderedDict):
     Used for serializing GIS values to GeoJSON values
     TODO: remove this when support for python 2.6/2.7 will be dropped
     """
+    def __init__(self, *args, **kwargs):
+        """
+        If a string is passed attempt to pass it through json.loads,
+        because it should be a geojson formatted string.
+        """
+        if args and isinstance(args[0], six.string_types):
+            try:
+                geojson = json.loads(args[0])
+                args = (geojson,)
+            except ValueError:
+                pass
+        super(GeoJsonDict, self).__init__(*args, **kwargs)
 
     def __str__(self):
         """
diff --git a/rest_framework_gis/filters.py b/rest_framework_gis/filters.py
index 8b27d38..596cafb 100644
--- a/rest_framework_gis/filters.py
+++ b/rest_framework_gis/filters.py
@@ -18,13 +18,18 @@ except ImportError:  # pragma: no cover
         'restframework-gis filters depend on package "django-filter" '
         'which is missing. Install with "pip install django-filter".'
     )
-
-try:  # pragma: no cover
-    # django >= 1.8
-    from django.contrib.gis.db.models.lookups import gis_lookups
-except ImportError:  # pragma: no cover
-    # django <= 1.7
-    gis_lookups = models.sql.query.ALL_TERMS
+try:
+    # Django >= 2.0
+    from django.contrib.gis.db.models.fields import BaseSpatialField
+except ImportError:
+    try:  # pragma: no cover
+        # django >= 1.8,<2.0
+        from django.contrib.gis.db.models.lookups import gis_lookups
+    except ImportError:  # pragma: no cover
+        # django <= 1.7
+        gis_lookups = models.sql.query.ALL_TERMS
+else:
+    gis_lookups = BaseSpatialField.get_lookups()
 
 
 __all__ = [
diff --git a/setup.cfg b/setup.cfg
index 2b08435..7633f81 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -2,7 +2,7 @@
 universal = 1
 
 [egg_info]
-tag_build = 
-tag_svn_revision = 0
 tag_date = 0
+tag_svn_revision = 0
+tag_build = 
 
diff --git a/tests/django_restframework_gis_tests/models.py b/tests/django_restframework_gis_tests/models.py
index 278bfe1..7de1800 100644
--- a/tests/django_restframework_gis_tests/models.py
+++ b/tests/django_restframework_gis_tests/models.py
@@ -14,7 +14,6 @@ class BaseModel(models.Model):
     slug = models.SlugField(max_length=128, unique=True, blank=True)
     timestamp = models.DateTimeField(null=True, blank=True)
     geometry = models.GeometryField()
-    objects = models.GeoManager()
 
     class Meta:
         abstract = True
diff --git a/tests/django_restframework_gis_tests/test_bbox.py b/tests/django_restframework_gis_tests/test_bbox.py
index e602789..510ba1e 100644
--- a/tests/django_restframework_gis_tests/test_bbox.py
+++ b/tests/django_restframework_gis_tests/test_bbox.py
@@ -1,7 +1,10 @@
 import json
 
 from django.test import TestCase
-from django.core.urlresolvers import reverse
+try:
+    from django.urls import reverse
+except ImportError:
+    from django.core.urlresolvers import reverse
 from django.core.exceptions import ImproperlyConfigured
 
 from rest_framework_gis import serializers as gis_serializers
diff --git a/tests/django_restframework_gis_tests/test_filters.py b/tests/django_restframework_gis_tests/test_filters.py
index 4e33ea1..431e7f1 100644
--- a/tests/django_restframework_gis_tests/test_filters.py
+++ b/tests/django_restframework_gis_tests/test_filters.py
@@ -6,7 +6,10 @@ from unittest import skipIf
 from django.conf import settings
 from django.test import TestCase
 from django.contrib.gis.geos import GEOSGeometry, Polygon
-from django.core.urlresolvers import reverse
+try:
+    from django.urls import reverse
+except ImportError:
+    from django.core.urlresolvers import reverse
 
 from .models import Location
 
diff --git a/tests/django_restframework_gis_tests/test_performance.py b/tests/django_restframework_gis_tests/test_performance.py
index a8ea081..d6625c5 100644
--- a/tests/django_restframework_gis_tests/test_performance.py
+++ b/tests/django_restframework_gis_tests/test_performance.py
@@ -7,7 +7,10 @@ from django.conf import settings
 # or by setting ``settings.TEST_PERFORMANCE`` to ``True``
 if 'django_restframework_gis_tests.test_performance' in sys.argv or settings.TEST_PERFORMANCE:
     from django.test import TestCase
-    from django.core.urlresolvers import reverse
+    try:
+        from django.urls import reverse
+    except ImportError:
+        from django.core.urlresolvers import reverse
     from rest_framework.renderers import JSONRenderer
     from rest_framework_gis import serializers as gis_serializers
     from contexttimer import Timer
@@ -34,6 +37,7 @@ if 'django_restframework_gis_tests.test_performance' in sys.argv or settings.TES
                 class Meta:
                     model = Location
                     geo_field = 'geometry'
+                    fields = '__all__'
             # create data
             self._create_data()
             # initialize serializer
diff --git a/tests/django_restframework_gis_tests/tests.py b/tests/django_restframework_gis_tests/tests.py
index fdf6076..2950d44 100644
--- a/tests/django_restframework_gis_tests/tests.py
+++ b/tests/django_restframework_gis_tests/tests.py
@@ -9,7 +9,10 @@ import pickle
 
 from django.test import TestCase
 from django.contrib.gis.geos import GEOSGeometry, Polygon, Point
-from django.core.urlresolvers import reverse
+try:
+    from django.urls import reverse
+except ImportError:
+    from django.core.urlresolvers import reverse
 from django.core.exceptions import ImproperlyConfigured
 
 from rest_framework_gis import serializers as gis_serializers
@@ -521,7 +524,7 @@ class TestRestFrameworkGis(TestCase):
         self.assertEqual(response.status_code, 200)
         self.assertEqual(response.data['properties']['name'], 'hidden geometry')
         self.assertEqual(response.data['geometry']['type'], 'Point')
-        self.assertEqual(response.data['geometry']['coordinates'], (0.0, 0.0))
+        self.assertEqual(response.data['geometry']['coordinates'], [0.0, 0.0])
 
     def test_geometry_serializer_method_field_none(self):
         location = Location.objects.create(name='None value', geometry='POINT (135.0 45.0)')
@@ -584,3 +587,57 @@ class TestRestFrameworkGis(TestCase):
         pickled = pickle.dumps(geojsondict)
         restored = pickle.loads(pickled)
         self.assertEqual(restored, geojsondict)
+
+    def test_geometrycollection_geojson(self):
+        """ test geometry collection geojson behaviour """
+        location = Location.objects.create(name='geometry collection geojson test',
+                                           geometry='GEOMETRYCOLLECTION ('
+                                                    'POINT (135.0 45.0),'
+                                                    'LINESTRING (135.0 45.0,140.0 50.0,145.0 55.0),'
+                                                    'POLYGON ((135.0 45.0,140.0 50.0,145.0 55.0,135.0 45.0)))')
+        url = reverse('api_geojson_location_details', args=[location.id])
+        expected = {
+            'id': location.id,
+            'type': 'Feature',
+            'properties': {
+                'details': "http://testserver/geojson/%s/" % location.id,
+                'name': 'geometry collection geojson test',
+                'fancy_name': 'Kool geometry collection geojson test',
+                'timestamp': None,
+                'slug': 'geometry-collection-geojson-test',
+            },
+            'geometry': {
+                'type': 'GeometryCollection',
+                'geometries': [
+                    {
+                        'type': 'Point',
+                        'coordinates': [135.0, 45.0]
+                    },
+                    {
+                        'type': 'LineString',
+                        'coordinates': [
+                            [135.0, 45.0],
+                            [140.0, 50.0],
+                            [145.0, 55.0]
+                        ]
+                    },
+                    {
+                        'type': 'Polygon',
+                        'coordinates': [
+                            [
+                                [135.0, 45.0],
+                                [140.0, 50.0],
+                                [145.0, 55.0],
+                                [135.0, 45.0],
+                            ]
+                        ]
+                    },
+                ],
+            }
+        }
+        response = self.client.get(url)
+        if sys.version_info > (3, 0, 0):
+            self.assertCountEqual(json.dumps(response.data), json.dumps(expected))
+        else:
+            self.assertItemsEqual(json.dumps(response.data), json.dumps(expected))
+        self.assertContains(response, "Kool geometry collection geojson test")
diff --git a/tests/django_restframework_gis_tests/views.py b/tests/django_restframework_gis_tests/views.py
index 4f1e012..7333b7d 100644
--- a/tests/django_restframework_gis_tests/views.py
+++ b/tests/django_restframework_gis_tests/views.py
@@ -1,5 +1,5 @@
+from django_filters.rest_framework import DjangoFilterBackend
 from rest_framework import generics
-from rest_framework.filters import DjangoFilterBackend
 from rest_framework_gis.filters import *
 from rest_framework_gis.pagination import GeoJsonPagination
 
diff --git a/tests/urls.py b/tests/urls.py
index 7975584..5111f37 100644
--- a/tests/urls.py
+++ b/tests/urls.py
@@ -1,10 +1,13 @@
-from django.conf.urls import include, url
+try:
+    from django.urls import include, url
+except ImportError:
+    from django.conf.urls import include, url
 from django.contrib import admin
 from django.contrib.staticfiles import views
 
 urlpatterns = [
     # Uncomment the next line to enable the admin:
-    url(r'^admin/', include(admin.site.urls)),
+    url(r'^admin/', admin.site.urls),
     # Uncomment the admin/doc line below to enable admin documentation:
     # url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/djangorestframework-gis.git



More information about the Python-modules-commits mailing list