Skip to content

Commit

Permalink
Fix projection of submitted reports
Browse files Browse the repository at this point in the history
  • Loading branch information
gutard committed Jul 27, 2015
1 parent d5f2336 commit 346088d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
9 changes: 9 additions & 0 deletions geotrek/feedback/serializers.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from django.contrib.gis.geos import GEOSGeometry
from rest_framework import serializers as rest_serializers

from geotrek.feedback import models as feedback_models
Expand All @@ -8,3 +9,11 @@ class Meta:
model = feedback_models.Report
geo_field = 'geom'
id_field = 'id'

def validate_geom(self, attrs, source):
if source not in attrs:
return attrs
geom = attrs[source]
point = GEOSGeometry(geom, srid=4326)
attrs[source] = point
return attrs
5 changes: 4 additions & 1 deletion geotrek/feedback/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def setUp(self):
super(CreateReportsAPITest, self).setUp()
self.add_url = '/api/en/reports/report'
self.data = {
'geom': '{"type": "Point", "coordinates": [0, 0]}',
'geom': '{"type": "Point", "coordinates": [3, 46.5]}',
'name': 'You Yeah',
'email': 'yeah@you.com'
}
Expand All @@ -63,6 +63,9 @@ def post_report_data(self, data):
def test_reports_can_be_created_using_post(self):
self.post_report_data(self.data)
self.assertTrue(feedback_models.Report.objects.filter(name='You Yeah').exists())
report = feedback_models.Report.objects.get()
self.assertAlmostEqual(report.geom.x, 700000)
self.assertAlmostEqual(report.geom.y, 6600000)

def test_reports_can_be_created_without_geom(self):
self.data.pop('geom')
Expand Down

0 comments on commit 346088d

Please sign in to comment.