summaryrefslogtreecommitdiff
path: root/ishtar_common
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2018-09-26 10:24:33 +0200
committerÉtienne Loks <etienne.loks@iggdrasil.net>2018-09-26 10:24:33 +0200
commit9a95a0d1765d9fa17d3149d7f875d129b6edc542 (patch)
treee924e158e3285c9a73510ab0743fe7901e360467 /ishtar_common
parentfa27623e72e78058d6d18161f3ebeb34a6020d5e (diff)
downloadIshtar-9a95a0d1765d9fa17d3149d7f875d129b6edc542.tar.bz2
Ishtar-9a95a0d1765d9fa17d3149d7f875d129b6edc542.zip
Area: add a reference field - Town: add 3 digit for num INSEE label
Diffstat (limited to 'ishtar_common')
-rw-r--r--ishtar_common/admin.py3
-rw-r--r--ishtar_common/migrations/0071_auto_20180926_1023.py25
-rw-r--r--ishtar_common/models.py17
3 files changed, 42 insertions, 3 deletions
diff --git a/ishtar_common/admin.py b/ishtar_common/admin.py
index 5a8afb416..6ae455e53 100644
--- a/ishtar_common/admin.py
+++ b/ishtar_common/admin.py
@@ -480,7 +480,8 @@ for model in general_models:
class AreaAdmin(GeneralTypeAdmin):
- list_display = ('label', 'parent', 'available')
+ list_display = ('label', 'reference', 'parent', 'available')
+ search_fields = ('label', 'reference')
list_filter = ('parent',)
model = models.Area
form = make_ajax_form(
diff --git a/ishtar_common/migrations/0071_auto_20180926_1023.py b/ishtar_common/migrations/0071_auto_20180926_1023.py
new file mode 100644
index 000000000..c508981ca
--- /dev/null
+++ b/ishtar_common/migrations/0071_auto_20180926_1023.py
@@ -0,0 +1,25 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.11.10 on 2018-09-26 10:23
+from __future__ import unicode_literals
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('ishtar_common', '0070_profiletypesummary'),
+ ]
+
+ operations = [
+ migrations.AddField(
+ model_name='area',
+ name='reference',
+ field=models.CharField(blank=True, max_length=200, null=True, verbose_name='Reference'),
+ ),
+ migrations.AlterField(
+ model_name='jsondatafield',
+ name='value_type',
+ field=models.CharField(choices=[(b'T', 'Text'), (b'LT', 'Long text'), (b'I', 'Integer'), (b'B', 'Boolean'), (b'F', 'Float'), (b'D', 'Date'), (b'C', 'Choices')], default=b'T', max_length=10, verbose_name='Type'),
+ ),
+ ]
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)