summaryrefslogtreecommitdiff
path: root/chimere/models.py
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@peacefrogs.net>2012-05-07 13:04:10 +0200
committerÉtienne Loks <etienne.loks@peacefrogs.net>2012-05-07 13:04:47 +0200
commit55a09a3c8f6446475b7a9c9693f19e5fb8830509 (patch)
treeb614d1f5be7b25ef67fb7d4397dd9a96fb91201d /chimere/models.py
parent7f06e73b305f7abcfcfd2968f65649f75b9d1a75 (diff)
downloadChimère-55a09a3c8f6446475b7a9c9693f19e5fb8830509.tar.bz2
Chimère-55a09a3c8f6446475b7a9c9693f19e5fb8830509.zip
Reactivate categories filtering by area
Diffstat (limited to 'chimere/models.py')
-rw-r--r--chimere/models.py22
1 files changed, 14 insertions, 8 deletions
diff --git a/chimere/models.py b/chimere/models.py
index 5fe213b..8b508a9 100644
--- a/chimere/models.py
+++ b/chimere/models.py
@@ -179,9 +179,6 @@ class SubCategory(models.Model):
# if there some restrictions with categories limit them
if area.subcategories.count():
sub_ids = [sub.id for sub in area.subcategories.all()]
- # if no area is defined for a category don't filter it
- sub_ids += [sub.id for sub in subcategories
- if not sub.areas.count()]
subcategories = subcategories.filter(id__in=sub_ids)
for sub_category in subcategories:
if sub_category.category not in sub_categories:
@@ -715,10 +712,21 @@ class SimpleArea:
return True
return False
- def getCategories(self, status='A', filter_available=True):
+ def getCategories(self, status='A', filter_available=True, area_name=None):
"""
Get categories for this area
"""
+ wheres = []
+ if area_name:
+ subcategory_pks = []
+ for cat, subcats in SubCategory.getAvailable(area_name=area_name):
+ for subcat in subcats:
+ subcategory_pks.append(unicode(subcat.pk))
+ if filter_available:
+ wheres += ['subcat.available = TRUE', 'cat.available = TRUE']
+ wheres += ['subcat.id in (%s)' % ",".join(subcategory_pks)]
+ where = " where " + " and ".join(wheres) if wheres else ""
+
equal_status = ''
if len(status) == 1:
equal_status = "='%s'" % status[0]
@@ -747,8 +755,7 @@ class SimpleArea:
sql += '''
inner join chimere_marker_categories mc on mc.subcategory_id=subcat.id and
mc.marker_id=mark.id'''
- if filter_available:
- sql += ' where subcat.available = TRUE and cat.available = TRUE'
+ sql += where
subcats = set(SubCategory.objects.raw(sql))
sql = sql_main + '''
inner join chimere_route rt on (ST_Intersects(%s, rt.route) or
@@ -759,8 +766,7 @@ class SimpleArea:
sql += '''
inner join chimere_route_categories rc on rc.subcategory_id=subcat.id and
rc.route_id=rt.id'''
- if filter_available:
- sql += ' where subcat.available = TRUE and cat.available = TRUE'
+ sql += where
subcats.union(SubCategory.objects.raw(sql))
return subcats