summaryrefslogtreecommitdiff
path: root/main/views.py
diff options
context:
space:
mode:
Diffstat (limited to 'main/views.py')
-rw-r--r--main/views.py22
1 files changed, 16 insertions, 6 deletions
diff --git a/main/views.py b/main/views.py
index 0c304ec..aba24f0 100644
--- a/main/views.py
+++ b/main/views.py
@@ -31,7 +31,7 @@ from django.core import serializers
from chimere import settings
from chimere.main.actions import actions
from chimere.main.models import SubCategory, PropertyModel, Marker, Route, \
- News, Area
+ News, Area, Color
from chimere.main.widgets import getMapJS, PointChooserWidget, \
RouteChooserWidget, URL_OSM_JS, URL_OSM_CSS
@@ -196,15 +196,25 @@ def getGeoObjects(request, category_ids, status='A'):
subcategory__in=category_ids.split('_'))
except:
return HttpResponse('no results')
- geo_objects = list(query)
+ query.order_by('subcategory')
+ routes = list(query)
+ jsons = []
+ current_cat, colors, idx = None, None, 0
+ for route in routes:
+ if not current_cat or current_cat != route.subcategory:
+ idx = 0
+ current_cat = route.subcategory
+ colors = list(Color.objects.filter(color_theme=\
+ route.subcategory.color_theme))
+ jsons.append(route.getGeoJSON(color=colors[idx % len(colors)].code))
+ idx += 1
try:
query = Marker.objects.filter(status__in=status,
subcategory__in=category_ids.split('_'))
except:
return HttpResponse('no results')
- geo_objects += list(query)
- if not geo_objects:
+ jsons += [geo_object.getGeoJSON() for geo_object in list(query)]
+ if not jsons:
return HttpResponse('no results')
- data = '{"type": "FeatureCollection", "features":[%s]}' % \
- ",".join([geo_object.getGeoJSON() for geo_object in geo_objects])
+ data = '{"type": "FeatureCollection", "features":[%s]}' % ",".join(jsons)
return HttpResponse(data)