diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2024-06-25 18:58:44 +0200 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2024-06-25 18:58:44 +0200 |
commit | f4eceb80557e2141e8535cc1b555c1a72e3e8ddd (patch) | |
tree | 59a1b1990f17f8c39dbd60462a54dd158020ffea /ishtar_common | |
parent | 1d416a4bb927fb501c452b2c7c4b1f3e9c3c8e0c (diff) | |
download | Ishtar-f4eceb80557e2141e8535cc1b555c1a72e3e8ddd.tar.bz2 Ishtar-f4eceb80557e2141e8535cc1b555c1a72e3e8ddd.zip |
✨ Notices - Town: add old town, new town reference on notices (refs #5380, #5732)
Diffstat (limited to 'ishtar_common')
-rw-r--r-- | ishtar_common/models_common.py | 12 | ||||
-rw-r--r-- | ishtar_common/templates/ishtar/sheet_town.html | 34 | ||||
-rw-r--r-- | ishtar_common/templatetags/window_field.py | 11 |
3 files changed, 43 insertions, 14 deletions
diff --git a/ishtar_common/models_common.py b/ishtar_common/models_common.py index ae4b5a64b..adc6ca9eb 100644 --- a/ishtar_common/models_common.py +++ b/ishtar_common/models_common.py @@ -3483,7 +3483,17 @@ class Town(GeographicItem, Imported, DocumentItem, MainItem, models.Model): for area in self.areas.all(): label.append(" - ") label.append(area.full_label) - return " ".join(label) + label = " ".join(label) + if self.children.count(): + label += str(_(", old town of ")) + " ; ".join([ + "{label} ({code})".format(label=p.name, code=p.numero_insee) + if p.numero_insee else p.name for p in self.children.all() + ]) + return label + + @property + def detail_label(self): + return self.label_with_areas def generate_geo(self, force=False): force = self.generate_limit(force=force) diff --git a/ishtar_common/templates/ishtar/sheet_town.html b/ishtar_common/templates/ishtar/sheet_town.html index 7b86b9bf1..448ea6752 100644 --- a/ishtar_common/templates/ishtar/sheet_town.html +++ b/ishtar_common/templates/ishtar/sheet_town.html @@ -75,22 +75,36 @@ </dl> {% endif %} {% field_flex "Department" item.departement %} + {% with has_image=item.images.count %} + {% if not has_image %} + </div> + </div> + {% endif %} + {% if has_image %} + </div></div> + {% endif %} + {% endwith %} + <hr class="clearfix"> + <div class="row"> {% if item.areas.count %} - <dl class="col-12 col-lg-6 flex-wrap"> + <dl class="col-12 flex-wrap"> <dt>{% trans "Areas" %}</dt> <dd>{% for area in item.areas.all %}{% if forloop.counter0 %} ; {% endif %}{{area}}{{area|simple_link_to_window}}{% endfor %}</dd> </dl> {% endif %} - {% with has_image=item.images.count %} - {% if not has_image %} - </div> + {% if item.children.count %} + <dl class="col-12 flex-wrap"> + <dt>{% trans "Old town of" %}</dt> + <dd>{% for town in item.children.all %}{% if forloop.counter0 %} ; {% endif %}{{town}}{{town|simple_link_to_window}}{% endfor %}</dd> + </dl> + {% endif %} + {% if item.parents.count %} + <dl class="col-12 flex-wrap"> + <dt>{% trans "New town for" %}</dt> + <dd>{% for town in item.parents.all %}{% if forloop.counter0 %} ; {% endif %}{{town}}{{town|simple_link_to_window}}{% endfor %}</dd> + </dl> + {% endif %} </div> - {% endif %} - {% if has_image %} - </div></div> - {% endif %} - {% endwith %} - <hr class="clearfix"> {% if PROFILE.mapping and item.main_geodata %} <h3>{% trans "Geographic localisation" %}</h3> <div class="row"> diff --git a/ishtar_common/templatetags/window_field.py b/ishtar_common/templatetags/window_field.py index d55a005e9..359330eb7 100644 --- a/ishtar_common/templatetags/window_field.py +++ b/ishtar_common/templatetags/window_field.py @@ -5,7 +5,7 @@ from django.template import loader from django.utils.translation import ugettext as _ from django.utils.safestring import mark_safe -from ishtar_common.models import HistoryModel +from ishtar_common.models import HistoryModel, Town from ishtar_common.templatetags.link_to_window import link_to_window register = template.Library() @@ -159,12 +159,15 @@ def field_flex_multiple_full(caption, data, small=False): @register.inclusion_tag('ishtar/blocks/window_field_detail.html', takes_context=True) def field_detail(context, caption, item, li=False, size=None): + label = item if isinstance(item, dict): for k in ("cached_label", "label", "common_name"): if k in item: - item = item[k] + label = item[k] break - return {'caption': caption, 'item': item, + elif hasattr(item, "detail_label"): + label = item.detail_label + return {'caption': caption, 'item': label, 'link': link_to_window(item, context), 'li': li, 'size': size} @@ -202,6 +205,8 @@ def field_flex_detail_multiple(context, caption, items, small=False, size=None): items = items.distinct().all() for item in items: link = link_to_window(item, context) + if hasattr(item, "detail_label"): + item = item.detail_label data.append({"item": item, "link": link}) dct = {'caption': caption, 'data': data, "size": size} return dct |