diff options
Diffstat (limited to 'chimere/models.py')
| -rw-r--r-- | chimere/models.py | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/chimere/models.py b/chimere/models.py index 44265eb..ca608e8 100644 --- a/chimere/models.py +++ b/chimere/models.py @@ -25,6 +25,7 @@ import simplejson as json from lxml import etree from datetime import datetime, timedelta from subprocess import Popen, PIPE +import unidecode from django.conf import settings from django.contrib.gis.db import models @@ -38,7 +39,7 @@ from django import forms from django.utils.translation import ugettext_lazy as _ from chimere.widgets import PointField, RouteField, SelectMultipleField, \ - TextareaWidget + TextareaWidget, DatePickerWidget from chimere.managers import BaseGeoManager from chimere.utils import KMLManager, OSMManager, ShapefileManager @@ -303,6 +304,15 @@ class Marker(GeographicItem): def __unicode__(self): return self.name + def __init__(self, *args, **kwargs): + super(Marker, self).__init__(*args, **kwargs) + # add read attributes for properties + for property in self.getProperties(): + attr_name = unidecode.unidecode(property.propertymodel.name).lower() + attr_name = re.sub(r'\W+','_', attr_name.strip()) + if not hasattr(self, attr_name): + setattr(self, attr_name, property.value) + def get_init_multi(self): multis = [forms.model_to_dict(multi) for multi in self.multimedia_files.all()] @@ -891,12 +901,19 @@ class PropertyModel(models.Model): name = models.CharField(_(u"Name"), max_length=150) order = models.IntegerField(_(u"Order")) available = models.BooleanField(_(u"Available")) + mandatory = models.BooleanField(_(u"Mandatory")) + subcategories = SelectMultipleField(SubCategory, related_name='properties', + blank=True, verbose_name=_(u"Restricted to theses sub-categories"), + help_text=_(u"If no sub-category is set all the property applies to all " + u"sub-categories")) TYPE = (('T', _('Text')), ('L', _('Long text')), - ('P', _('Password'))) + ('P', _('Password')), + ('D', _("Date"))) TYPE_WIDGET = {'T':forms.TextInput, 'L':TextareaWidget, - 'P':forms.PasswordInput} + 'P':forms.PasswordInput, + 'D':DatePickerWidget} type = models.CharField(_(u"Type"), max_length=1, choices=TYPE) def __unicode__(self): return self.name |
