summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2016-05-26 00:07:19 +0200
committerÉtienne Loks <etienne.loks@iggdrasil.net>2016-05-26 00:07:19 +0200
commit2270d2b21c2b928c9a6c90afbd0069bd126656ad (patch)
tree5fca84c12663d3f78a5493fe061a46afad7e8049
parenteb49d9126ef91d39f238fe9fa19ee21490d5ef42 (diff)
downloadChimère-2270d2b21c2b928c9a6c90afbd0069bd126656ad.tar.bz2
Chimère-2270d2b21c2b928c9a6c90afbd0069bd126656ad.zip
Property models are now filtered by area in getDetail
-rw-r--r--chimere/forms.py18
-rw-r--r--chimere/models.py17
-rw-r--r--chimere/templates/chimere/detail.html2
-rw-r--r--chimere/views.py1
4 files changed, 19 insertions, 19 deletions
diff --git a/chimere/forms.py b/chimere/forms.py
index 0d866a7..580fb09 100644
--- a/chimere/forms.py
+++ b/chimere/forms.py
@@ -25,7 +25,7 @@ from django import forms
from django.conf import settings
from django.core.exceptions import ImproperlyConfigured
from django.core.urlresolvers import reverse
-from django.db.models import Q, Count
+from django.db.models import Q
from django.forms.formsets import formset_factory
from django.utils.translation import ugettext as _
from django.contrib.auth.models import User, Permission, ContentType
@@ -273,13 +273,7 @@ class MarkerAdminFormBase(forms.ModelForm):
area_name = None
if 'area_name' in keys:
area_name = keys.pop('area_name')
- q = PropertyModel.objects.filter(available=True)
- if area_name:
- # areas__count__gt=0 necessary to prevent Django bug
- q = q.annotate(Count('areas'))\
- .filter(
- (Q(areas__urn=area_name) & Q(areas__count__gt=0)) |
- Q(areas__count=0))
+ q = PropertyModel.getAvailable(area_name=area_name)
self.pms = [pm for pm in q.all()]
if 'instance' in keys and keys['instance']:
instance = keys['instance']
@@ -432,13 +426,7 @@ class RouteAdminForm(forms.ModelForm):
area_name = None
if 'area_name' in keys:
area_name = keys.pop('area_name')
- q = PropertyModel.objects.filter(available=True)
- if area_name:
- # areas__count__gt=0 necessary to prevent Django bug
- q = q.annotate(Count('areas'))\
- .filter(
- (Q(areas__urn=area_name) & Q(areas__count__gt=0)) |
- Q(areas__count=0))
+ q = PropertyModel.getAvailable(area_name=area_name)
self.pms = [pm for pm in q.all()]
if 'instance' in keys and keys['instance']:
instance = keys['instance']
diff --git a/chimere/models.py b/chimere/models.py
index d9b388d..ddeeefd 100644
--- a/chimere/models.py
+++ b/chimere/models.py
@@ -38,7 +38,7 @@ from django.contrib.gis.db import models
from django.core.files import File
from django.core.exceptions import ObjectDoesNotExist
from django.core.urlresolvers import reverse
-from django.db.models import Q
+from django.db.models import Q, Count
from django.db.models.signals import post_save, pre_save, m2m_changed
from django.template import defaultfilters
from django.utils.translation import ugettext_lazy as _
@@ -577,11 +577,11 @@ class GeographicItem(models.Model):
return
return property
- def getProperties(self):
+ def getProperties(self, area_name=None):
"""Get all the property availables
"""
properties = []
- for pm in PropertyModel.objects.filter(available=True):
+ for pm in PropertyModel.getAvailable(area_name=area_name):
property = self.getProperty(pm)
if property:
properties.append(property)
@@ -1851,6 +1851,17 @@ class PropertyModel(models.Model):
'''
return 'property_%d_%d' % (self.order, self.id)
+ @classmethod
+ def getAvailable(cls, area_name=None):
+ q = cls.objects.filter(available=True)
+ if not area_name:
+ return q.annotate(Count('areas')).filter(areas__count=0)
+ # areas__count__gt=0 necessary to prevent Django bug
+ return q.annotate(Count('areas'))\
+ .filter(
+ (Q(areas__urn=area_name) & Q(areas__count__gt=0)) |
+ Q(areas__count=0))
+
class PropertyModelChoice(models.Model):
'''Choices for property model
diff --git a/chimere/templates/chimere/detail.html b/chimere/templates/chimere/detail.html
index dbf0cb8..11ce8d2 100644
--- a/chimere/templates/chimere/detail.html
+++ b/chimere/templates/chimere/detail.html
@@ -20,7 +20,7 @@
{% if marker.description %}
<p class='description'>{{ marker.description|sanitize:"p b i br hr strong em img:src:alt span:style a:href:target ul li ol h1 h2 h3 h4 table td tr th"|safe}}</p>
{% endif %}
- {% for property in marker.getProperties %}
+ {% for property in properties %}
<p class='{{property.propertymodel.getNamedId}}'><strong>{{property.propertymodel}}</strong>{% trans ":" %} {{ property.value|sanitize:"p b i br hr strong em img:src:alt span:style a:href:target ul li ol h1 h2 h3 h4 table td tr th"|safe}}</p>
{% endfor %}
{% if marker.origin %}<p class='detail_source'><strong>{% trans "Source:" %}</strong> <span>{{marker.origin}}</span></p>{% endif %}
diff --git a/chimere/views.py b/chimere/views.py
index 77f3d0b..8c2c52c 100644
--- a/chimere/views.py
+++ b/chimere/views.py
@@ -654,6 +654,7 @@ def getDetail(request, area_name, key):
response_dct['dated'] = settings.CHIMERE_DAYS_BEFORE_EVENT \
and marker.start_date
response_dct['routing_enabled'] = settings.CHIMERE_ENABLE_ROUTING
+ response_dct['properties'] = marker.getProperties(area_name=area_name)
return render_to_response('chimere/detail.html', response_dct,
context_instance=RequestContext(request))