diff options
Diffstat (limited to 'ishtar_common/models.py')
| -rw-r--r-- | ishtar_common/models.py | 17 | 
1 files changed, 15 insertions, 2 deletions
diff --git a/ishtar_common/models.py b/ishtar_common/models.py index 07b4002ff..e862885d0 100644 --- a/ishtar_common/models.py +++ b/ishtar_common/models.py @@ -3808,8 +3808,14 @@ class Town(Imported, models.Model):      def _generate_cached_label(self):          cached_label = self.name -        if settings.COUNTRY == "fr": -            cached_label = u"%s - %s" % (self.name, self.numero_insee[:2]) +        if settings.COUNTRY == "fr" and self.numero_insee: +            dpt_len = 2 +            if self.numero_insee.startswith('97') or \ +                    self.numero_insee.startswith('98') or \ +                    self.numero_insee[0] not in ('0', '1', '2', '3', '4', '5', +                                                 '6', '7', '8', '9'): +                dpt_len = 3 +            cached_label = u"%s - %s" % (self.name, self.numero_insee[:dpt_len])          if self.year and self.children.count():              cached_label += u" ({})".format(self.year)          return cached_label @@ -3838,6 +3844,8 @@ m2m_changed.connect(town_child_changed, sender=Town.children.through)  class Area(HierarchicalType):      towns = models.ManyToManyField(Town, verbose_name=_(u"Towns"), blank=True,                                     related_name='areas') +    reference = models.CharField(_(u"Reference"), max_length=200, blank=True, +                                 null=True)      parent = models.ForeignKey(          'self', blank=True, null=True, verbose_name=_(u"Parent"),          help_text=_(u"Only four level of parent are managed."), @@ -3849,6 +3857,11 @@ class Area(HierarchicalType):          verbose_name_plural = _(u"Areas")          ordering = ('parent__label', 'label') +    def __unicode__(self): +        if not self.reference: +            return self.label +        return u"{} ({})".format(self.label, self.reference) +  class OperationType(GeneralType):      order = models.IntegerField(_(u"Order"), default=1)  | 
