[Python-modules-commits] [djangorestframework-gis] 01/07: Import djangorestframework-gis_0.9.6.orig.tar.gz

Michael Fladischer fladi at moszumanska.debian.org
Wed Nov 4 10:01:37 UTC 2015


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

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

commit 1a7f03a322870cd1700e0998393401fe27e0ce76
Author: Michael Fladischer <FladischerMichael at fladi.at>
Date:   Wed Nov 4 09:39:39 2015 +0100

    Import djangorestframework-gis_0.9.6.orig.tar.gz
---
 .travis.yml                                        | 11 ++++-
 CHANGES.rst                                        |  9 +++++
 README.rst                                         | 13 +++---
 rest_framework_gis/__init__.py                     |  2 +-
 rest_framework_gis/serializers.py                  | 47 +++++++++++++---------
 setup.py                                           |  1 +
 tests/django_restframework_gis_tests/models.py     |  1 +
 .../django_restframework_gis_tests/serializers.py  | 20 +++++++--
 tests/django_restframework_gis_tests/tests.py      | 18 ++++++---
 tests/django_restframework_gis_tests/urls.py       |  3 +-
 tests/django_restframework_gis_tests/views.py      | 14 +++++--
 11 files changed, 99 insertions(+), 40 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index 6bb8d12..3b06548 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -6,6 +6,7 @@ services:
   - postgresql
 
 python:
+  - "3.5"
   - "3.4"
   - "3.3"
   - "3.2"
@@ -13,17 +14,23 @@ python:
   - "2.6"
 
 env:
-  - DJANGO="django==1.8.4"
+  - DJANGO="django==1.8.5"
   - DJANGO="django==1.7.10"
   - DJANGO="django==1.6.11"
   - DJANGO="django==1.5.12"
 
 matrix:
   exclude:
+    - python: "3.5"
+      env: DJANGO="django==1.7.10"
+    - python: "3.5"
+      env: DJANGO="django==1.6.11"
+    - python: "3.5"
+      env: DJANGO="django==1.5.12"
     - python: "2.6"
       env: DJANGO="django==1.7.10"
     - python: "2.6"
-      env: DJANGO="django==1.8.4"
+      env: DJANGO="django==1.8.5"
 
 branches:
   only:
diff --git a/CHANGES.rst b/CHANGES.rst
index 5b5b178..5d29b46 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -1,6 +1,15 @@
 Changelog
 =========
 
+Version 0.9.6 [2015-11-02]
+--------------------------
+
+- `#82 <https://github.com/djangonauts/django-rest-framework-gis/issues/82>`_: avoid ``KeyError`` id field not in ``fields`` (bug introduced in 0.9.5)
+- `fbaf9b1 <https://github.com/djangonauts/django-rest-framework-gis/commit/fbaf9b1>`_: improved documentation for new default ``id_field`` behaviour
+- `#84 <https://github.com/djangonauts/django-rest-framework-gis/pull/84>`_: switched to ``assertAlmostEqual`` in ``test_post_location_list_EWKT`` to ease testing for debian package
+- `#85 <https://github.com/djangonauts/django-rest-framework-gis/pull/85>`_: fixed serialization of properties holding ``None`` values (bug introduced in 0.9.5)
+- `#86 <https://github.com/djangonauts/django-rest-framework-gis/pull/86>`_: updated advertised compatibility to include **python 3.5**
+
 Version 0.9.5 [2015-10-12]
 --------------------------
 
diff --git a/README.rst b/README.rst
index e0a40b1..48f3f15 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.9.6**        **3.1.X** to **3.3.X**       **1.5.x** to **1.8** **2.6** to **3.5**
 **0.9.5**        **3.1.X** to **3.2.X**       **1.5.x** to **1.8** **2.6** to **3.4**
 **0.9.4**        **3.1.X** to **3.2.X**       **1.5.x** to **1.8** **2.6** to **3.4**
 **0.9.3**        **3.1.X**                    **1.5.x** to **1.8** **2.6** to **3.4**
@@ -249,8 +250,11 @@ Specifying the ID: "id_field"
 #############################
 
 The primary key of the model (usually the "id" attribute) is
-automatically put outside the "properties" object (before "type") unless
-``id_field`` is set to False:
+automatically used as the ``id`` field of each
+`GeoJSON Feature Object <https://tools.ietf.org/html/draft-butler-geojson#section-2.2>`_.
+
+The default behaviour follows the `GeoJSON RFC <https://tools.ietf.org/html/draft-butler-geojson>`_,
+but it can be disbaled by setting ``id_field`` to ``False``:
 
 .. code-block:: python
 
@@ -264,8 +268,7 @@ automatically put outside the "properties" object (before "type") unless
             id_field = False
             fields = ('id', 'address', 'city', 'state')
 
-You could also set the ``id_field`` to some other unique field in
-your model, like **"slug"**:
+The ``id_field`` can also be set to use some other unique field in your model, eg: ``slug``:
 
 .. code-block:: python
 
@@ -300,7 +303,7 @@ read access for a REST client and can be achieved using ``auto_bbox``. Example:
 
 
 The second approach uses the ``bbox_geo_field`` to specify an addional
-GeometryField of the model which will be used to calculate the bounding box. This allows
+``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
 be saved as Polygons. Example:
diff --git a/rest_framework_gis/__init__.py b/rest_framework_gis/__init__.py
index 343f1bf..dbbbc6b 100644
--- a/rest_framework_gis/__init__.py
+++ b/rest_framework_gis/__init__.py
@@ -1,4 +1,4 @@
-VERSION = (0, 9, 5, 'final')
+VERSION = (0, 9, 6, 'final')
 __version__ = VERSION  # alias
 
 
diff --git a/rest_framework_gis/serializers.py b/rest_framework_gis/serializers.py
index 8e0f86d..de22933 100644
--- a/rest_framework_gis/serializers.py
+++ b/rest_framework_gis/serializers.py
@@ -48,38 +48,44 @@ class GeoFeatureModelSerializer(ModelSerializer):
 
     def __init__(self, *args, **kwargs):
         super(GeoFeatureModelSerializer, self).__init__(*args, **kwargs)
-        self.Meta.id_field = getattr(self.Meta, 'id_field', self.Meta.model._meta.pk.name)
-        if not hasattr(self.Meta, 'geo_field') or not self.Meta.geo_field:
+        meta = getattr(self, 'Meta')
+        default_id_field = None
+        primary_key = self.Meta.model._meta.pk.name
+        # use primary key as id_field when possible
+        if not hasattr(meta, 'fields') or primary_key in meta.fields:
+            default_id_field = primary_key
+        meta.id_field = getattr(meta, 'id_field', default_id_field)
+
+        if not hasattr(meta, 'geo_field') or not meta.geo_field:
             raise ImproperlyConfigured("You must define a 'geo_field'.")
 
         def check_excludes(field_name, field_role):
             """make sure the field is not excluded"""
-            if hasattr(self.Meta, 'exclude') and field_name in self.Meta.exclude:
+            if hasattr(meta, 'exclude') and field_name in meta.exclude:
                 raise ImproperlyConfigured("You cannot exclude your '{0}'.".format(field_role))
 
         def add_to_fields(field_name):
             """Make sure the field is included in the fields"""
-            if hasattr(self.Meta, 'fields'):
-                if field_name not in self.Meta.fields:
-                    if type(self.Meta.fields) is tuple:
+            if hasattr(meta, 'fields'):
+                if field_name not in meta.fields:
+                    if type(meta.fields) is tuple:
                         additional_fields = (field_name,)
                     else:
                         additional_fields = [field_name]
-                    self.Meta.fields += additional_fields
+                    meta.fields += additional_fields
 
-        check_excludes(self.Meta.geo_field, 'geo_field')
-        add_to_fields(self.Meta.geo_field)
+        check_excludes(meta.geo_field, 'geo_field')
+        add_to_fields(meta.geo_field)
 
-        self.Meta.bbox_geo_field = getattr(self.Meta, 'bbox_geo_field', None)
-        if self.Meta.bbox_geo_field:
-            check_excludes(self.Meta.bbox_geo_field, 'bbox_geo_field')
-            add_to_fields(self.Meta.bbox_geo_field)
+        meta.bbox_geo_field = getattr(meta, 'bbox_geo_field', None)
+        if meta.bbox_geo_field:
+            check_excludes(meta.bbox_geo_field, 'bbox_geo_field')
+            add_to_fields(meta.bbox_geo_field)
 
-        self.Meta.auto_bbox = getattr(self.Meta, 'auto_bbox', False)
-        if self.Meta.bbox_geo_field and self.Meta.auto_bbox:
-            raise ImproperlyConfigured(
-                "You must eiher define a 'bbox_geo_field' or 'auto_bbox', but you can not set both"
-            )
+        meta.auto_bbox = getattr(meta, 'auto_bbox', False)
+        if meta.bbox_geo_field and meta.auto_bbox:
+            raise ImproperlyConfigured("You must eiher define a 'bbox_geo_field' or "
+                                       "'auto_bbox', but you can not set both")
 
     def to_representation(self, instance):
         """
@@ -145,7 +151,10 @@ class GeoFeatureModelSerializer(ModelSerializer):
             if field.write_only:
                 continue
             value = field.get_attribute(instance)
-            properties[field.field_name] = field.to_representation(value)
+            representation = None
+            if value is not None:
+                representation = field.to_representation(value)
+            properties[field.field_name] = representation
 
         return properties
 
diff --git a/setup.py b/setup.py
index 556b21b..dc9f433 100644
--- a/setup.py
+++ b/setup.py
@@ -55,5 +55,6 @@ setup(
         'Programming Language :: Python :: 3',
         'Programming Language :: Python :: 3.3',
         'Programming Language :: Python :: 3.4',
+        'Programming Language :: Python :: 3.5',
     ]
 )
diff --git a/tests/django_restframework_gis_tests/models.py b/tests/django_restframework_gis_tests/models.py
index f9c5fdd..278bfe1 100644
--- a/tests/django_restframework_gis_tests/models.py
+++ b/tests/django_restframework_gis_tests/models.py
@@ -12,6 +12,7 @@ __all__ = [
 class BaseModel(models.Model):
     name = models.CharField(max_length=32)
     slug = models.SlugField(max_length=128, unique=True, blank=True)
+    timestamp = models.DateTimeField(null=True, blank=True)
     geometry = models.GeometryField()
     objects = models.GeoManager()
 
diff --git a/tests/django_restframework_gis_tests/serializers.py b/tests/django_restframework_gis_tests/serializers.py
index 93b5ecb..c4e767e 100644
--- a/tests/django_restframework_gis_tests/serializers.py
+++ b/tests/django_restframework_gis_tests/serializers.py
@@ -11,7 +11,8 @@ __all__ = [
     'PaginatedLocationGeoSerializer',
     'LocationGeoFeatureSerializer',
     'LocationGeoFeatureSlugSerializer',
-    'LocationGeoFeatureFalseIDSerializer',
+    'LocationGeoFeatureFalseIdSerializer',
+    'LocationGeoFeatureNoIdSerializer',
     'LocatedFileGeoFeatureSerializer',
     'BoxedLocationGeoFeatureSerializer',
     'LocationGeoFeatureBboxSerializer',
@@ -53,10 +54,10 @@ class LocationGeoFeatureSlugSerializer(LocationGeoFeatureSerializer):
         model = Location
         geo_field = 'geometry'
         id_field = 'slug'
-        fields = ('name', 'slug')
+        fields = ('name', 'slug', 'timestamp')
 
 
-class LocationGeoFeatureFalseIDSerializer(LocationGeoFeatureSerializer):
+class LocationGeoFeatureFalseIdSerializer(LocationGeoFeatureSerializer):
     """ id attribute set as False """
     class Meta:
         model = Location
@@ -64,6 +65,17 @@ class LocationGeoFeatureFalseIDSerializer(LocationGeoFeatureSerializer):
         id_field = False
 
 
+class LocationGeoFeatureNoIdSerializer(LocationGeoFeatureSerializer):
+    """
+    id attribute left out, issue #82
+    see: https://github.com/djangonauts/django-rest-framework-gis/issues/82
+    """
+    class Meta:
+        model = Location
+        geo_field = 'geometry'
+        fields = ('name',)
+
+
 class LocatedFileGeoFeatureSerializer(gis_serializers.GeoFeatureModelSerializer):
     """ located file geo serializer  """
     details = serializers.HyperlinkedIdentityField(view_name='api_geojson_located_file_details')
@@ -86,7 +98,7 @@ class BoxedLocationGeoFeatureSerializer(gis_serializers.GeoFeatureModelSerialize
         model = BoxedLocation
         geo_field = 'geometry'
         bbox_geo_field = 'bbox_geometry'
-        fields = ['name', 'details', 'id']
+        fields = ['name', 'details', 'id', 'timestamp']
 
 
 class LocationGeoFeatureBboxSerializer(gis_serializers.GeoFeatureModelSerializer):
diff --git a/tests/django_restframework_gis_tests/tests.py b/tests/django_restframework_gis_tests/tests.py
index c7e4470..5e68205 100644
--- a/tests/django_restframework_gis_tests/tests.py
+++ b/tests/django_restframework_gis_tests/tests.py
@@ -132,10 +132,8 @@ class TestRestFrameworkGis(TestCase):
         expected_coords = (6.381495826183805, 53.384066927384985)
         self.assertEqual(response.status_code, 201)
         self.assertEqual(Location.objects.count(), 1)
-        self.assertEquals(
-            Location.objects.get(name='EWKT input test').geometry.coords,
-            expected_coords
-        )
+        for l, e in zip(Location.objects.get(name='EWKT input test').geometry.coords, expected_coords):
+            self.assertAlmostEqual(l, e, places=5)
 
     def test_post_location_list_WKT_as_json(self):
         self.assertEqual(Location.objects.count(), 0)
@@ -228,6 +226,7 @@ class TestRestFrameworkGis(TestCase):
                 'details': "http://testserver/geojson/%s/" % location.id,
                 'name': 'geojson test',
                 'fancy_name': 'Kool geojson test',
+                'timestamp': None,
                 'slug': 'geojson-test',
             },
             'geometry': {
@@ -259,9 +258,18 @@ class TestRestFrameworkGis(TestCase):
         self.assertEqual(response.data['id'], location.slug)
 
     def test_geojson_false_id_attribute_slug(self):
-        location = Location.objects.create(name='geojson test', geometry='POINT (10.1 10.1)')
+        location = Location.objects.create(name='falseid test', geometry='POINT (10.1 10.1)')
         url = reverse('api_geojson_location_falseid_details', args=[location.id])
         response = self.client.get(url)
+        self.assertEqual(response.data['properties']['name'], 'falseid test')
+        with self.assertRaises(KeyError):
+            response.data['id']
+
+    def test_geojson_no_id_attribute_slug(self):
+        location = Location.objects.create(name='noid test', geometry='POINT (10.1 10.1)')
+        url = reverse('api_geojson_location_noid_details', args=[location.id])
+        response = self.client.get(url)
+        self.assertEqual(response.data['properties']['name'], 'noid test')
         with self.assertRaises(KeyError):
             response.data['id']
 
diff --git a/tests/django_restframework_gis_tests/urls.py b/tests/django_restframework_gis_tests/urls.py
index 03b051f..8df2837 100644
--- a/tests/django_restframework_gis_tests/urls.py
+++ b/tests/django_restframework_gis_tests/urls.py
@@ -12,6 +12,7 @@ urlpatterns = patterns('django_restframework_gis_tests.views',
     url(r'^geojson_none/(?P<pk>[0-9]+)/$', 'geojson_location_details_none', name='api_geojson_location_details_none'),
     url(r'^geojson/(?P<slug>[-\w]+)/$', 'geojson_location_slug_details', name='api_geojson_location_slug_details'),
     url(r'^geojson-falseid/(?P<pk>[0-9]+)/$', 'geojson_location_falseid_details', name='api_geojson_location_falseid_details'),
+    url(r'^geojson-noid/(?P<pk>[0-9]+)/$', 'geojson_location_noid_details', name='api_geojson_location_noid_details'),
 
     # file
     url(r'^geojson-file/(?P<pk>[0-9]+)/$', 'geojson_located_file_details', name='api_geojson_located_file_details'),
@@ -22,7 +23,7 @@ urlpatterns = patterns('django_restframework_gis_tests.views',
 
     # geojson with bbox with autogenerated bbox
     url(r'^geojson-with-auto-bbox/$', 'geojson_location_bbox_list', name='api_geojson_location_bbox_list'),
-    
+
     # Filters
     url(r'^filters/contained_in_bbox$', 'geojson_location_contained_in_bbox_list', name='api_geojson_location_list_contained_in_bbox_filter'),
     url(r'^filters/overlaps_bbox$', 'geojson_location_overlaps_bbox_list', name='api_geojson_location_list_overlaps_bbox_filter'),
diff --git a/tests/django_restframework_gis_tests/views.py b/tests/django_restframework_gis_tests/views.py
index 457c86c..04d0342 100644
--- a/tests/django_restframework_gis_tests/views.py
+++ b/tests/django_restframework_gis_tests/views.py
@@ -115,12 +115,20 @@ class GeojsonLocationSlugDetails(generics.RetrieveUpdateDestroyAPIView):
 geojson_location_slug_details = GeojsonLocationSlugDetails.as_view()
 
 
-class GeojsonLocationFalseIDDetails(generics.RetrieveUpdateDestroyAPIView):
+class GeojsonLocationFalseIdDetails(generics.RetrieveUpdateDestroyAPIView):
     model = Location
-    serializer_class = LocationGeoFeatureFalseIDSerializer
+    serializer_class = LocationGeoFeatureFalseIdSerializer
     queryset = Location.objects.all()
 
-geojson_location_falseid_details = GeojsonLocationFalseIDDetails.as_view()
+geojson_location_falseid_details = GeojsonLocationFalseIdDetails.as_view()
+
+
+class GeojsonLocationNoIdDetails(generics.RetrieveUpdateDestroyAPIView):
+    model = Location
+    serializer_class = LocationGeoFeatureNoIdSerializer
+    queryset = Location.objects.all()
+
+geojson_location_noid_details = GeojsonLocationNoIdDetails.as_view()
 
 
 class LocationFilter(GeoFilterSet):

-- 
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