From 20af4c9ba0d7675ee0675c3a04a24d06b5344f39 Mon Sep 17 00:00:00 2001 From: Matthias Date: Sat, 17 Apr 2021 23:48:47 +0200 Subject: [PATCH] template tag for translatable alerts with links --- InvenTree/build/templates/build/build_base.html | 7 +++++-- InvenTree/part/templates/part/part_base.html | 3 ++- InvenTree/part/templatetags/inventree_extras.py | 10 ++++++++++ InvenTree/stock/templates/stock/item_base.html | 8 ++++++-- 4 files changed, 23 insertions(+), 5 deletions(-) diff --git a/InvenTree/build/templates/build/build_base.html b/InvenTree/build/templates/build/build_base.html index a8e5e53377..9da515c2f6 100644 --- a/InvenTree/build/templates/build/build_base.html +++ b/InvenTree/build/templates/build/build_base.html @@ -3,6 +3,7 @@ {% load static %} {% load i18n %} {% load status_codes %} +{% load inventree_extras %} {% block page_title %} InvenTree | {% trans "Build Order" %} - {{ build }} @@ -11,12 +12,14 @@ InvenTree | {% trans "Build Order" %} - {{ build }} {% block pre_content %} {% if build.sales_order %}
- {% trans "This Build Order is allocated to Sales Order" %} {{ build.sales_order }} + {% object_link 'so-detail' build.sales_order.id build.sales_order as link %} + {% blocktrans %}This Build Order is allocated to Sales Order {{ link }}{% endblocktrans %}
{% endif %} {% if build.parent %}
- {% trans "This Build Order is a child of Build Order" %} {{ build.parent }} + {% object_link 'build-detail' build.parent.id build.parent as link %} + {% blocktrans %}This Build Order is a child of Build Order {{ link }}{% endblocktrans %}
{% endif %} {% endblock %} diff --git a/InvenTree/part/templates/part/part_base.html b/InvenTree/part/templates/part/part_base.html index f11fe879ce..a0a058fa3f 100644 --- a/InvenTree/part/templates/part/part_base.html +++ b/InvenTree/part/templates/part/part_base.html @@ -14,7 +14,8 @@ {% if part.variant_of %}
- {% trans "This part is a variant of" %} {{ part.variant_of.full_name }} + {% object_link 'part-variants' part.variant_of.id part.variant_of.full_name as link %} + {% blocktrans %}This part is a variant of {{ link }}{% endblocktrans %}
{% endif %} diff --git a/InvenTree/part/templatetags/inventree_extras.py b/InvenTree/part/templatetags/inventree_extras.py index c0dc15c2b0..8366b37f23 100644 --- a/InvenTree/part/templatetags/inventree_extras.py +++ b/InvenTree/part/templatetags/inventree_extras.py @@ -4,6 +4,8 @@ over and above the built-in Django tags. import os from django import template +from django.urls import reverse +from django.utils.safestring import mark_safe from InvenTree import version, settings import InvenTree.helpers @@ -164,3 +166,11 @@ def authorized_owners(group): pass return owners + + +@register.simple_tag() +def object_link(url_name, pk, ref): + """ Return highlighted link to object """ + + ref_url = reverse(url_name, kwargs={'pk': pk}) + return mark_safe('{}'.format(ref_url, ref)) diff --git a/InvenTree/stock/templates/stock/item_base.html b/InvenTree/stock/templates/stock/item_base.html index b955acda9c..23397c9886 100644 --- a/InvenTree/stock/templates/stock/item_base.html +++ b/InvenTree/stock/templates/stock/item_base.html @@ -48,13 +48,17 @@ InvenTree | {% trans "Stock Item" %} - {{ item }} {% for allocation in item.sales_order_allocations.all %}
- {% trans "This stock item is allocated to Sales Order" %} #{{ allocation.line.order }} ({% trans "Quantity" %}: {% decimal allocation.quantity %}) + {% object_link 'so-detail' allocation.line.order.id allocation.line.order as link %} + {% define decimal allocation.quantity as qty %} + {% blocktrans %}This stock item is allocated to Sales Order {{ link }} (Quantity: {{ qty }}){% endblocktrans %}
{% endfor %} {% for allocation in item.allocations.all %}
- {% trans "This stock item is allocated to Build" %} #{{ allocation.build }} ({% trans "Quantity" %}: {% decimal allocation.quantity %}) + {% object_link 'build-detail' allocation.build.id allocation.build %} + {% define decimal allocation.quantity as qty %} + {% blocktrans %}This stock item is allocated to Build {{ link }} (Quantity: {{ qty }}){% endblocktrans %}
{% endfor %}