From f4eceb80557e2141e8535cc1b555c1a72e3e8ddd Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Tue, 25 Jun 2024 18:58:44 +0200 Subject: ✨ Notices - Town: add old town, new town reference on notices (refs #5380, #5732) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ishtar_common/models_common.py | 12 ++++++++- ishtar_common/templates/ishtar/sheet_town.html | 34 ++++++++++++++++++-------- ishtar_common/templatetags/window_field.py | 11 ++++++--- 3 files changed, 43 insertions(+), 14 deletions(-) (limited to 'ishtar_common') 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 @@ {% endif %} {% field_flex "Department" item.departement %} + {% with has_image=item.images.count %} + {% if not has_image %} + + + {% endif %} + {% if has_image %} + + {% endif %} + {% endwith %} +
+
{% if item.areas.count %} -
+
{% trans "Areas" %}
{% for area in item.areas.all %}{% if forloop.counter0 %} ; {% endif %}{{area}}{{area|simple_link_to_window}}{% endfor %}
{% endif %} - {% with has_image=item.images.count %} - {% if not has_image %} -
+ {% if item.children.count %} +
+
{% trans "Old town of" %}
+
{% for town in item.children.all %}{% if forloop.counter0 %} ; {% endif %}{{town}}{{town|simple_link_to_window}}{% endfor %}
+
+ {% endif %} + {% if item.parents.count %} +
+
{% trans "New town for" %}
+
{% for town in item.parents.all %}{% if forloop.counter0 %} ; {% endif %}{{town}}{{town|simple_link_to_window}}{% endfor %}
+
+ {% endif %} - {% endif %} - {% if has_image %} - - {% endif %} - {% endwith %} -
{% if PROFILE.mapping and item.main_geodata %}

{% trans "Geographic localisation" %}

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 -- cgit v1.2.3