summaryrefslogtreecommitdiff
path: root/chimere/models.py
diff options
context:
space:
mode:
Diffstat (limited to 'chimere/models.py')
-rw-r--r--chimere/models.py30
1 files changed, 21 insertions, 9 deletions
diff --git a/chimere/models.py b/chimere/models.py
index 566b4fe..caddefc 100644
--- a/chimere/models.py
+++ b/chimere/models.py
@@ -660,6 +660,18 @@ 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}}'
for cat in self.categories.all():
if categories_id and cat.id not in categories_id:
continue
@@ -668,16 +680,16 @@ class Marker(GeographicItem):
'icon_path':cat.icon.image,
'icon_hover_path':cat.hover_icon.image \
if cat.hover_icon else '',
- 'icon_width':cat.icon.image.width,
- 'icon_height':cat.icon.image.height,
'category_name':json.dumps(cat.name)}
- jsons.append(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}}' % items)
+ try:
+ items.update({'icon_width':cat.icon.image.width,
+ 'icon_height':cat.icon.image.height,})
+ cjson = full_json % items
+ except IOError:
+ cjson = light_json % items
+
+ jsons.append(cjson)
+
return ",".join(jsons)
@property