diff options
Diffstat (limited to 'chimere/models.py')
-rw-r--r-- | chimere/models.py | 63 |
1 files changed, 37 insertions, 26 deletions
diff --git a/chimere/models.py b/chimere/models.py index 4c77211..15d264b 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 @@ -427,6 +427,8 @@ class GeographicItem(models.Model): submiter_comment = models.TextField(_(u"Submitter comment"), max_length=200, blank=True, null=True) status = models.CharField(_(u"Status"), max_length=1, choices=STATUS) + keywords = models.TextField(_(u"Keywords"), max_length=200, + blank=True, null=True) import_key = models.CharField(_(u"Import key"), max_length=200, blank=True, null=True) import_version = models.IntegerField(_(u"Import version"), @@ -695,35 +697,45 @@ class Marker(GeographicItem): '''Return a GeoJSON string ''' jsons = [] + 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 '', - 'icon_width':cat.icon.image.width, - 'icon_height':cat.icon.image.height, - 'category_name':json.dumps(cat.name),} + 'category_name':cat.name}) items['weight'] = '' if cat.weighted: if not self.weight: continue + items['weight'] = self.weight + if cat.color_theme and cat.color_theme.colors.count(): + items['colors'] += ["#%s"] % '", "#'.join( + [color.code for color in cat.color_theme.colors.\ + order_by('order').all()]) + try: + items['properties'].update({'icon_width':cat.icon.image.width, + 'icon_height':cat.icon.image.height,}) + except IOError: + pass + if cat.weighted: + if not self.weight: + continue items['weight'] = u', "weight":%d' % self.weight if cat.color_theme and cat.color_theme.colors.count(): items['weight'] += u', "colors":["#%s"]' % '", "#'.join( [color.code for color in cat.color_theme.colors.\ order_by('order').all()]) - 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'\ - u'%(weight)s}}' % items) - return ",".join(jsons) + + jsons.append(items) + + return json.dumps(jsons) @property def default_category(self): @@ -1196,11 +1208,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, @@ -1295,11 +1307,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: """ |