diff options
| author | Étienne Loks <etienne.loks@peacefrogs.net> | 2010-11-19 01:26:06 +0100 |
|---|---|---|
| committer | Étienne Loks <etienne.loks@peacefrogs.net> | 2010-11-19 01:26:06 +0100 |
| commit | c2ae3613c662973bd1fd78f415f57bb0e4f16272 (patch) | |
| tree | 8f4d40fe75c2f86d3d577012407c522b1070d9de | |
| parent | f19d83a2ea0c6fce6e5da8f637a68dc4a758270b (diff) | |
| download | Chimère-c2ae3613c662973bd1fd78f415f57bb0e4f16272.tar.bz2 Chimère-c2ae3613c662973bd1fd78f415f57bb0e4f16272.zip | |
Display only checked categories for object in multiple categories (fixes #271)
| -rw-r--r-- | chimere/main/models.py | 4 | ||||
| -rw-r--r-- | chimere/main/views.py | 8 |
2 files changed, 8 insertions, 4 deletions
diff --git a/chimere/main/models.py b/chimere/main/models.py index 0528357..a2a3785 100644 --- a/chimere/main/models.py +++ b/chimere/main/models.py @@ -246,11 +246,13 @@ Format YYYY-MM-DD")) properties.append(property) return properties - def getGeoJSON(self): + def getGeoJSON(self, categories_id=[]): '''Return a GeoJSON string ''' jsons = [] for cat in self.categories.all(): + if categories_id and cat.id not in categories_id: + continue jsons.append("""{"type":"Feature", "geometry":%(geometry)s, \ "properties":{"pk": %(id)d, "name": "%(name)s", \ "icon_path":"%(icon_path)s", "icon_width":%(icon_width)d, \ diff --git a/chimere/main/views.py b/chimere/main/views.py index 3092eb9..f16241f 100644 --- a/chimere/main/views.py +++ b/chimere/main/views.py @@ -275,9 +275,10 @@ def getGeoObjects(request, area_name, category_ids, status): if not status: status = 'A' status = status.split('_') + category_ids = category_ids.split('_') try: query = Route.objects.filter(status__in=status, - categories__in=category_ids.split('_')) + categories__in=category_ids) except: return HttpResponse('no results') query.order_by('categories') @@ -294,10 +295,11 @@ def getGeoObjects(request, area_name, category_ids, status): idx += 1 try: query = Marker.objects.filter(status__in=status, - categories__in=category_ids.split('_')) + categories__in=category_ids) except: return HttpResponse('no results') - jsons += [geo_object.getGeoJSON() for geo_object in list(query)] + category_ids = [int(cat_id) for cat_id in category_ids] + jsons += [geo_object.getGeoJSON(category_ids) for geo_object in list(query)] if not jsons: return HttpResponse('no results') data = '{"type": "FeatureCollection", "features":[%s]}' % ",".join(jsons) |
