summaryrefslogtreecommitdiff
path: root/chimere/models.py
diff options
context:
space:
mode:
Diffstat (limited to 'chimere/models.py')
-rw-r--r--chimere/models.py73
1 files changed, 44 insertions, 29 deletions
diff --git a/chimere/models.py b/chimere/models.py
index 757e464..be84036 100644
--- a/chimere/models.py
+++ b/chimere/models.py
@@ -20,7 +20,7 @@
"""
Models description
"""
-import os, datetime, pyexiv2, re, string
+import os, datetime, pyexiv2, re, string, copy
import simplejson as json
from lxml import etree
from PIL import Image
@@ -229,6 +229,8 @@ class SubCategory(models.Model):
default=False)
routing_warn = models.BooleanField(_(u"Routing warn"), default=False)
order = models.IntegerField(_(u"Order"), default=1000)
+ keywords = models.TextField(_(u"Keywords"), max_length=200,
+ blank=True, null=True)
def __unicode__(self):
return u"%s / %s" % (self.category.name, self.name)
class Meta:
@@ -299,6 +301,14 @@ class SubCategory(models.Model):
json_string = json.dumps(self.getJSONDict())
return json_string
+ @property
+ def slug(self):
+ return defaultfilters.slugify(self.name)
+
+ @property
+ def item_nb(self):
+ return Marker.objects.filter(categories=self).count()
+
STATUS = (('S', _(u'Submited')),
('A', _(u'Available')),
('M', _(u'Modified')),
@@ -424,6 +434,8 @@ class GeographicItem(models.Model):
submiter_comment = models.TextField(_(u"Submitter comment"), max_length=200,
blank=True, null=True)
status = models.CharField(_(u"Status"), max_length=1, choices=STATUS)
+ keywords = models.TextField(_(u"Keywords"), max_length=200,
+ blank=True, null=True)
import_key = models.CharField(_(u"Import key"), max_length=200,
blank=True, null=True)
import_version = models.IntegerField(_(u"Import version"),
@@ -665,31 +677,34 @@ class Marker(GeographicItem):
'''Return a GeoJSON string
'''
jsons = []
+ json_tpl = {"type":"Feature", "properties":{}}
for cat in self.categories.all():
if categories_id and cat.id not in categories_id:
continue
- items = {'id':self.id, 'name':json.dumps(self.name),
- 'geometry':self.point.geojson,
- 'icon_path':cat.icon.image,
- 'icon_hover_path':cat.hover_icon.image \
+ items = copy.deepcopy(json_tpl)
+ items['geometry'] = json.loads(self.point.geojson)
+ items['properties'].update({
+ 'pk':self.id,
+ 'name':self.name,
+ 'icon_path':unicode(cat.icon.image),
+ 'icon_hover_path':unicode(cat.hover_icon.image) \
if cat.hover_icon else '',
- 'icon_width':cat.icon.image.width,
- 'icon_height':cat.icon.image.height,
- 'category_name':json.dumps(cat.name)}
- jsons.append(u'{"type":"Feature", "geometry":%(geometry)s, '\
- u'"properties":{"pk": %(id)d, "name": %(name)s, '\
- u'"icon_path":"%(icon_path)s", '\
- u'"icon_hover_path":"%(icon_hover_path)s", '\
- u'"icon_width":%(icon_width)d, '\
- u'"icon_height":%(icon_height)d, '\
- u'"category_name":%(category_name)s}}' % items)
- return ",".join(jsons)
+ 'category_name':cat.name})
+ try:
+ items['properties'].update({'icon_width':cat.icon.image.width,
+ 'icon_height':cat.icon.image.height,})
+ except IOError:
+ pass
+
+ jsons.append(items)
+
+ return json.dumps(jsons)
@property
def default_category(self):
# Should we select only available ones ?
# Should we catch if not exists ?
- cats = self.categories
+ cats = self.categories.filter(available=True, category__available=True)
if cats.count():
return cats.all()[0]
@@ -702,7 +717,6 @@ class Marker(GeographicItem):
url = reverse('chimere:tiny', args=[area_name, urn])
return url
-
PRE_ATTRS = {
'Marker':('name', 'description', 'start_date', 'geometry', 'import_version',
'modified_since_import'),
@@ -1152,11 +1166,11 @@ class Route(GeographicItem):
'''
if '#' not in color:
color = '#' + color
- attributes = {'id':self.id, 'name':json.dumps(self.name),
- 'color':color, 'geometry':self.route.geojson,}
- return u'{"type":"Feature", "geometry":%(geometry)s, '\
- u'"properties":{"pk": %(id)d, "name": %(name)s, '\
- u'"color":"%(color)s"}}' % attributes
+ attributes = {"type":"Feature",
+ "geometry":json.loads(self.route.geojson),
+ "properties":{"pk":self.id, "name":self.name,
+ "color":color}}
+ return json.dumps(attributes)
def getTinyUrl(self):
parameters = 'current_feature=%d&checked_categories=%s' % (self.id,
@@ -1251,11 +1265,10 @@ class AggregatedRoute(models.Model):
'''
if '#' not in color:
color = '#' + color
- attributes = {'id':self.id, 'name':json.dumps(u'Aggregated route'),
- 'color':color, 'geometry':self.route.geojson,}
- return u'{"type":"Feature", "geometry":%(geometry)s, '\
- u'"properties":{"pk": %(id)d, "name": %(name)s, '\
- u'"color":"%(color)s"}}' % attributes
+ attributes = {'color':color, 'geometry':json.loads(self.route.geojson),
+ 'type':"Feature", "properties":{"pk": self.id,
+ "name": u'Aggregated route',}}
+ return json.dumps(attributes)
class SimplePoint:
"""
@@ -1549,12 +1562,14 @@ class PropertyModel(models.Model):
('P', _('Password')),
('D', _("Date")),
('C', _("Choices")),
+ ('B', _("Boolean")),
)
TYPE_WIDGET = {'T':forms.TextInput,
'L':TextareaWidget,
'P':forms.PasswordInput,
'D':DatePickerWidget,
- 'C':forms.Select
+ 'C':forms.Select,
+ 'B':forms.CheckboxInput,
}
type = models.CharField(_(u"Type"), max_length=1, choices=TYPE)
def __unicode__(self):