From caf3138871b7cba6d76a83d4d7ae5123fddf1b8e Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Thu, 20 Mar 2025 14:31:50 +0100 Subject: 🩹 sheet - geo: limit display of values MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../templates/ishtar/sheet_operation.html | 4 ++-- ishtar_common/models_common.py | 2 +- ishtar_common/templates/ishtar/blocks/sheet_geographic.html | 4 ++-- ishtar_common/templatetags/ishtar_helpers.py | 11 +++++++++++ 4 files changed, 16 insertions(+), 5 deletions(-) diff --git a/archaeological_operations/templates/ishtar/sheet_operation.html b/archaeological_operations/templates/ishtar/sheet_operation.html index 4d078a998..ef9c9632a 100644 --- a/archaeological_operations/templates/ishtar/sheet_operation.html +++ b/archaeological_operations/templates/ishtar/sheet_operation.html @@ -151,9 +151,9 @@ {% if next or item.cached_towns_label %} {% trans "Towns" %} {% if next %} - {{ item|m2m_listing:'towns'|join:" ; "|default:'' }} + {{ item|m2m_listing:'towns'|join:" ; "|default:''|limit_label }} {% else %} - {{ item.cached_towns_label }} + {{ item.cached_towns_label|limit_label }} {% endif %} {% endif %} diff --git a/ishtar_common/models_common.py b/ishtar_common/models_common.py index e2495bcd5..d7b7c3e21 100644 --- a/ishtar_common/models_common.py +++ b/ishtar_common/models_common.py @@ -2519,7 +2519,7 @@ class GeoVectorData(Imported, OwnPerms): @property def source_label(self): - return str(self.source) + return str(self.source or "-") def display_coordinates_3d(self): return self.display_coordinates(dim=3) diff --git a/ishtar_common/templates/ishtar/blocks/sheet_geographic.html b/ishtar_common/templates/ishtar/blocks/sheet_geographic.html index 6212c9573..d860293a8 100644 --- a/ishtar_common/templates/ishtar/blocks/sheet_geographic.html +++ b/ishtar_common/templates/ishtar/blocks/sheet_geographic.html @@ -18,9 +18,9 @@ {% if geo.id == geo_item.main_geodata_id %}{% else %}–{% endif %} {% if geo.data_type %}{{ geo.data_type }}{% else %}-{% endif %} - {{ geo.source_label }} + {{ geo.source_label|limit_label:120 }} {{ geo.geometry_type_label }} - {{ geo.name }} + {{ geo.name|limit_label:120 }} {% if geo.origin %}{{ geo.origin }}{% else %}-{% endif %} {% if geo.provider %}{{ geo.provider }}{% else %}-{% endif %} {% if geo.acquisition_date %}{{ geo.acquisition_date|date:"DATE_FORMAT"|default:"-" }}{% else %}-{% endif %} diff --git a/ishtar_common/templatetags/ishtar_helpers.py b/ishtar_common/templatetags/ishtar_helpers.py index b668b8f0b..ece121a8e 100644 --- a/ishtar_common/templatetags/ishtar_helpers.py +++ b/ishtar_common/templatetags/ishtar_helpers.py @@ -133,3 +133,14 @@ def user_can_do(ishtar_user, permission): @register.filter def format_date(value): return python_format_date(value) + + +@register.filter +def limit_label(value, limit=120): + value = str(value or "") + if len(value) <= limit: + return value + value = value.replace('"', '\\"') + return mark_safe( + f'{value[:(limit - 4)]} (...)' + ) -- cgit v1.2.3