diff options
Diffstat (limited to 'chimere/models.py')
-rw-r--r-- | chimere/models.py | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/chimere/models.py b/chimere/models.py index fc2dc94..a1e00f9 100644 --- a/chimere/models.py +++ b/chimere/models.py @@ -880,7 +880,10 @@ class Marker(GeographicItem): if categories_id and cat.id not in categories_id: continue items = copy.deepcopy(json_tpl) - items['geometry'] = json.loads(self.point.geojson) + try: + items['geometry'] = json.loads(self.point.geojson) + except json.JSONDecodeError: + continue items['properties'].update({ 'pk': self.id, 'key': "marker-{}".format(self.id), @@ -1019,8 +1022,12 @@ class Polygon(GeographicItem): def getGeoJSON(self, color="#000", inner_color='#0F0'): '''Return a GeoJSON string ''' + try: + geom = json.loads(self.polygon.geojson) + except json.JSONDecodeError: + return json.dumps('{}') attributes = {"type": "Feature", - "geometry": json.loads(self.polygon.geojson), + "geometry": geom, "properties": {"pk": self.id, "name": self.name, 'key': "polygon-{}".format(self.pk), "color": self.color or color, @@ -1518,8 +1525,12 @@ class Route(GeographicItem): def getGeoJSON(self, color="#000"): '''Return a GeoJSON string ''' + try: + geom = json.loads(self.route.geojson) + except json.JSONDecodeError: + return json.dumps('{}') attributes = {"type": "Feature", - "geometry": json.loads(self.route.geojson), + "geometry": geom, "properties": {"pk": self.id, "name": self.name, 'key': "route-{}".format(self.pk), "color": color}} @@ -1633,8 +1644,12 @@ class AggregatedRoute(models.Model): ''' if '#' not in color: color = '#' + color + try: + geom = json.loads(self.route.geojson) + except json.JSONDecodeError: + return json.dumps('{}') attributes = { - 'color': color, 'geometry': json.loads(self.route.geojson), + 'color': color, 'geometry': geom, 'type': "Feature", "properties": { 'key': "aggroute-{}".format(self.pk), "pk": self.id, "name": u'Aggregated route'}} |