template tag for translatable alerts with links

This commit is contained in:
Matthias 2021-04-17 23:48:47 +02:00
parent 7a0a901c2b
commit 20af4c9ba0
4 changed files with 23 additions and 5 deletions

View File

@ -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 %}
<div class='alert alert-block alert-info'>
{% trans "This Build Order is allocated to Sales Order" %} <b><a href="{% url 'so-detail' build.sales_order.id %}">{{ build.sales_order }}</a></b>
{% object_link 'so-detail' build.sales_order.id build.sales_order as link %}
{% blocktrans %}This Build Order is allocated to Sales Order {{ link }}{% endblocktrans %}
</div>
{% endif %}
{% if build.parent %}
<div class='alert alert-block alert-info'>
{% trans "This Build Order is a child of Build Order" %} <b><a href="{% url 'build-detail' build.parent.id %}">{{ build.parent }}</a></b>
{% object_link 'build-detail' build.parent.id build.parent as link %}
{% blocktrans %}This Build Order is a child of Build Order {{ link }}{% endblocktrans %}
</div>
{% endif %}
{% endblock %}

View File

@ -14,7 +14,8 @@
{% if part.variant_of %}
<div class='alert alert-info alert-block'>
{% trans "This part is a variant of" %} <strong><a href="{% url 'part-variants' part.variant_of.id %}">{{ part.variant_of.full_name }}</a></strong>
{% object_link 'part-variants' part.variant_of.id part.variant_of.full_name as link %}
{% blocktrans %}This part is a variant of {{ link }}{% endblocktrans %}
</div>
{% endif %}

View File

@ -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('<b><a href="{}">{}</a></b>'.format(ref_url, ref))

View File

@ -48,13 +48,17 @@ InvenTree | {% trans "Stock Item" %} - {{ item }}
{% for allocation in item.sales_order_allocations.all %}
<div class='alert alert-block alert-info'>
{% trans "This stock item is allocated to Sales Order" %} <a href="{% url 'so-detail' allocation.line.order.id %}"><b>#{{ allocation.line.order }}</b></a> ({% 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 %}
</div>
{% endfor %}
{% for allocation in item.allocations.all %}
<div class='alert alert-block alert-info'>
{% trans "This stock item is allocated to Build" %} <a href="{% url 'build-detail' allocation.build.id %}"><b>#{{ allocation.build }}</b></a> ({% 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 %}
</div>
{% endfor %}