summaryrefslogtreecommitdiff
path: root/main/models.py
diff options
context:
space:
mode:
authoretienne <etienne@9215b0d5-fb2c-4bbd-8d3e-bd2e9090e864>2009-01-11 13:16:21 +0000
committeretienne <etienne@9215b0d5-fb2c-4bbd-8d3e-bd2e9090e864>2009-01-11 13:16:21 +0000
commit03c7e15227fb84b94d9f870aac69d7d54b61889a (patch)
treec7d4c5e276fd3092449c195b8c354f7ebe645979 /main/models.py
parent4182d638dcbe194b65b38d1ae92068dadbefc84d (diff)
downloadChimère-03c7e15227fb84b94d9f870aac69d7d54b61889a.tar.bz2
Chimère-03c7e15227fb84b94d9f870aac69d7d54b61889a.zip
Modification of created routes
git-svn-id: http://www.peacefrogs.net/svn/chimere/trunk@9 9215b0d5-fb2c-4bbd-8d3e-bd2e9090e864
Diffstat (limited to 'main/models.py')
-rw-r--r--main/models.py74
1 files changed, 73 insertions, 1 deletions
diff --git a/main/models.py b/main/models.py
index f449d09..ead8a85 100644
--- a/main/models.py
+++ b/main/models.py
@@ -26,7 +26,7 @@ from django.contrib.gis.db import models
from django.contrib import admin
from chimere import settings
-from chimere.main.widgets import PointField
+from chimere.main.widgets import PointField, RouteField
class News(models.Model):
@@ -163,6 +163,78 @@ class Marker(models.Model):
'icon_width':self.subcategory.icon.image.width,
'icon_height':self.subcategory.icon.image.height,}
+class Route(models.Model):
+ '''Route on the map
+ '''
+ name = models.CharField(_("Name"), max_length=150)
+ subcategory = models.ForeignKey(SubCategory, verbose_name=_("Subcategory"))
+ route = RouteField(_("Route"))
+ picture = models.ImageField(_("Image"), upload_to='upload', blank=True,
+ height_field='height', width_field='width')
+ STATUS = (('S', _('Submited')),
+ ('A', _('Available')),
+ ('D', _('Disabled')),)
+ STATUS_DCT = {}
+ for key, label in STATUS:
+ STATUS_DCT[key] = label
+ status = models.CharField(_("Status"), max_length=1, choices=STATUS)
+ objects = models.GeoManager()
+
+ def __unicode__(self):
+ return self.name
+
+ class Meta:
+ ordering = ('subcategory__category', 'subcategory', 'status', 'name')
+ verbose_name = _("Route")
+
+ def getLatitude(self):
+ '''Return the latitude
+ '''
+ return self.point.y
+
+ def getLongitude(self):
+ '''Return the longitude
+ '''
+ return self.point.x
+
+ def getProperty(self, propertymodel, safe=None):
+ """Get the property of an associated property model.
+ If safe set to True, verify if the property is available
+ """
+ if safe and not propertymodel.available:
+ return
+ try:
+ property = Property.objects.get(propertymodel=propertymodel,
+ marker=self)
+ except Property.DoesNotExist:
+ return
+ return property
+
+ def getProperties(self):
+ """Get all the property availables
+ """
+ properties = []
+ for pm in PropertyModel.objects.filter(available=True):
+ property = self.getProperty(pm)
+ if property:
+ properties.append(property)
+ return properties
+
+ def getGeoJSON(self):
+ '''Return a GeoJSON string
+ '''
+ return """{"type":"Feature", "geometry":{"type":"Point", \
+"crs": "EPSG:%(epsg)d", "coordinates":[%(longitude)s, %(latitude)s]}, \
+"properties":{"pk": %(id)d, "name": "%(name)s", \
+"icon_path":"%(icon_path)s", "icon_width":%(icon_width)d, \
+"icon_height":%(icon_height)d}}""" % {'id':self.id, 'name':self.name,
+'icon_path':self.subcategory.icon.image, 'latitude':self.getLatitude(),
+'longitude':self.getLongitude(), 'epsg':settings.EPSG_PROJECTION,
+'icon_width':self.subcategory.icon.image.width,
+'icon_height':self.subcategory.icon.image.height,}
+
+
+
class PropertyModel(models.Model):
'''Model for a property
'''