diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2016-09-20 18:08:06 +0200 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2016-09-20 18:08:06 +0200 |
commit | 5628412da85a36a655d2d5002bbfbfcb25ac7bcd (patch) | |
tree | 5fc4ddd09b16bfae9ed98a169d8245384d8a6f68 /chimere/views.py | |
parent | 90972102ac176f5cd8715cae15663f069a01f176 (diff) | |
download | Chimère-5628412da85a36a655d2d5002bbfbfcb25ac7bcd.tar.bz2 Chimère-5628412da85a36a655d2d5002bbfbfcb25ac7bcd.zip |
Fix non aggregated routes getter - better performances for route getter
Diffstat (limited to 'chimere/views.py')
-rw-r--r-- | chimere/views.py | 66 |
1 files changed, 38 insertions, 28 deletions
diff --git a/chimere/views.py b/chimere/views.py index c713d6c..12ae9bd 100644 --- a/chimere/views.py +++ b/chimere/views.py @@ -820,35 +820,45 @@ def _getGeoObjects(area_name, category_ids, status='A', getjson=True, # routes if 'Route' in item_types: # TODO: manage non aggregated and bounding box in non-aggregated - query = AggregatedRoute.objects.filter( - status__in=status, subcategory__in=category_ids).order_by( - 'subcategory', '-pk') - if getjson: - current_cat, colors, idx = None, None, 0 - for route in query.all(): - color = "" - # aggregated view has no color and no categories - if hasattr(route, 'color') and route.color: - color = route.color - elif hasattr(route, 'categories'): - c_cat = None - for cat in route.categories.all(): - if cat.id in category_ids: - c_cat = cat - break - if c_cat and not current_cat or current_cat != c_cat: - idx = 0 - current_cat = c_cat - colors = list(Color.objects.filter( - color_theme=c_cat.color_theme)) - if colors: - color = colors[idx % len(colors)].code - idx += 1 - else: - color = "#000" - items.append(json.loads(route.getGeoJSON(color=color))) + if aggregated_category_ids: + query = AggregatedRoute.objects.filter( + status__in=status, subcategory__in=category_ids).order_by( + 'subcategory', '-pk') + if getjson: + current_cat, colors, idx = None, None, 0 + for route in query.all(): + color = "" + # aggregated view has no color and no categories + if hasattr(route, 'color') and route.color: + color = route.color + elif hasattr(route, 'categories'): + c_cat = None + for cat in route.categories.all(): + if cat.id in category_ids: + c_cat = cat + break + if c_cat and not current_cat or current_cat != c_cat: + idx = 0 + current_cat = c_cat + colors = list(Color.objects.filter( + color_theme=c_cat.color_theme)) + if colors: + color = colors[idx % len(colors)].code + idx += 1 + else: + color = "#000" + items.append(json.loads(route.getGeoJSON(color=color))) + else: + items += list(query) else: - items += list(query) + query = Route.objects.filter( + status__in=status, categories__pk__in=category_ids) + if getjson: + current_cat, colors, idx = None, None, 0 + items += Route.getGeoJSONs( + query, limit_to_categories=category_ids) + else: + items += list(query) if not items: return empty, zoom_need_reload |