summaryrefslogtreecommitdiff
path: root/chimere/models.py
diff options
context:
space:
mode:
Diffstat (limited to 'chimere/models.py')
-rw-r--r--chimere/models.py55
1 files changed, 22 insertions, 33 deletions
diff --git a/chimere/models.py b/chimere/models.py
index caddefc..2ae8481 100644
--- a/chimere/models.py
+++ b/chimere/models.py
@@ -20,7 +20,7 @@
"""
Models description
"""
-import os, datetime, pyexiv2, re, string
+import os, datetime, pyexiv2, re, string, copy
import simplejson as json
from lxml import etree
from PIL import Image
@@ -660,37 +660,27 @@ class Marker(GeographicItem):
'''Return a GeoJSON string
'''
jsons = []
- full_json = u'{"type":"Feature", "geometry":%(geometry)s, '\
- u'"properties":{"pk": %(id)d, "name": %(name)s, '\
- u'"icon_path":"%(icon_path)s", '\
- u'"icon_hover_path":"%(icon_hover_path)s", '\
- u'"icon_width":%(icon_width)d, '\
- u'"icon_height":%(icon_height)d, '\
- u'"category_name":%(category_name)s}}'
- light_json = u'{"type":"Feature", "geometry":%(geometry)s, '\
- u'"properties":{"pk": %(id)d, "name": %(name)s, '\
- u'"icon_path":"%(icon_path)s", '\
- u'"icon_hover_path":"%(icon_hover_path)s", '\
- u'"category_name":%(category_name)s}}'
+ json_tpl = {"type":"Feature", "properties":{}}
for cat in self.categories.all():
if categories_id and cat.id not in categories_id:
continue
- items = {'id':self.id, 'name':json.dumps(self.name),
- 'geometry':self.point.geojson,
- 'icon_path':cat.icon.image,
+ items = copy.deepcopy(json_tpl)
+ items['geometry'] = json.loads(self.point.geojson)
+ items['properties'].update({'pk':self.id,
+ 'name':self.name,
+ 'icon_path':unicode(cat.icon.image),
'icon_hover_path':cat.hover_icon.image \
if cat.hover_icon else '',
- 'category_name':json.dumps(cat.name)}
+ 'category_name':cat.name})
try:
- items.update({'icon_width':cat.icon.image.width,
- 'icon_height':cat.icon.image.height,})
- cjson = full_json % items
+ items['properties'].update({'icon_width':cat.icon.image.width,
+ 'icon_height':cat.icon.image.height,})
except IOError:
- cjson = light_json % items
+ pass
- jsons.append(cjson)
+ jsons.append(items)
- return ",".join(jsons)
+ return json.dumps(jsons)
@property
def default_category(self):
@@ -1156,11 +1146,11 @@ class Route(GeographicItem):
'''
if '#' not in color:
color = '#' + color
- attributes = {'id':self.id, 'name':json.dumps(self.name),
- 'color':color, 'geometry':self.route.geojson,}
- return u'{"type":"Feature", "geometry":%(geometry)s, '\
- u'"properties":{"pk": %(id)d, "name": %(name)s, '\
- u'"color":"%(color)s"}}' % attributes
+ attributes = {"type":"Feature",
+ "geometry":json.loads(self.route.geojson),
+ "properties":{"pk":self.id, "name":self.name,
+ "color":color}}
+ return json.dumps(attributes)
def getTinyUrl(self):
parameters = 'current_feature=%d&checked_categories=%s' % (self.id,
@@ -1255,11 +1245,10 @@ class AggregatedRoute(models.Model):
'''
if '#' not in color:
color = '#' + color
- attributes = {'id':self.id, 'name':json.dumps(u'Aggregated route'),
- 'color':color, 'geometry':self.route.geojson,}
- return u'{"type":"Feature", "geometry":%(geometry)s, '\
- u'"properties":{"pk": %(id)d, "name": %(name)s, '\
- u'"color":"%(color)s"}}' % attributes
+ attributes = {'color':color, 'geometry':json.loads(self.route.geojson),
+ 'type':"Feature", "properties":{"pk": self.id,
+ "name": u'Aggregated route',}}
+ return json.dumps(attributes)
class SimplePoint:
"""