From f0ad9524c56aeb1af01358eb7b0f7a545305bd03 Mon Sep 17 00:00:00 2001 From: rasmus Date: Sat, 28 Jun 2025 21:04:43 +0300 Subject: [PATCH] Linkify location in item view --- inventory-app/main.py | 11 +++++++++++ inventory-app/templates/inventory_view.html | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/inventory-app/main.py b/inventory-app/main.py index af6be45..4ce1254 100755 --- a/inventory-app/main.py +++ b/inventory-app/main.py @@ -84,6 +84,16 @@ def render_qr_code(slug): qr = segno.make(str("http://k6.ee/" + slug), micro=False, mode='byte', mask=3, error='L', boost_error=False) return Markup(qr.svg_inline(light='black', dark='yellow', scale=3, border=1)) +def render_location_link(location: str): + if location == "": + return + + linkstart = location.find("k6.ee/") + if linkstart == -1: + return + + return location[linkstart:].split(" ", 1)[0] + jinja2.filters.FILTERS['format_name'] = format_name jinja2.filters.FILTERS['markdown'] = render_markdown jinja2.filters.FILTERS['timeago'] = render_timeago @@ -95,6 +105,7 @@ jinja2.filters.FILTERS['quote_plus'] = lambda u: urllib.parse.quote_plus(u) jinja2.filters.FILTERS['check_foreign_key_format'] = check_foreign_key_format jinja2.filters.FILTERS['display_name'] = render_user_display_name jinja2.filters.FILTERS['qr_code'] = render_qr_code +jinja2.filters.FILTERS['location_link'] = render_location_link env = Environment(loader=FileSystemLoader('templates/')) diff --git a/inventory-app/templates/inventory_view.html b/inventory-app/templates/inventory_view.html index 0910cb3..8014e05 100644 --- a/inventory-app/templates/inventory_view.html +++ b/inventory-app/templates/inventory_view.html @@ -22,7 +22,7 @@ Location - {{ item.location }} + {% if item.location and (item.location | location_link) %}🡼{% else %}🮰{% endif %} {{ item.location }} Last audited