Expose more status code data to the templates

- Status codes are now exposed globally to every page
- Much simplified so wow
- https://stackoverflow.com/questions/3221592/how-to-pass-common-dictionary-data-to-every-page-in-django
This commit is contained in:
Oliver Walters 2020-04-24 09:18:37 +10:00
parent 2c9b112562
commit b45fec221c
11 changed files with 45 additions and 36 deletions

View File

@ -0,0 +1,19 @@
# -*- coding: utf-8 -*-
"""
Provides extra global data to all templates.
"""
from InvenTree.status_codes import SalesOrderStatus, PurchaseOrderStatus
from InvenTree.status_codes import BuildStatus, StockStatus
def status_codes(request):
return {
# Expose the StatusCode classes to the templates
'SalesOrderStatus': SalesOrderStatus,
'PurchaseOrderStatus': PurchaseOrderStatus,
'BuildStatus': BuildStatus,
'StockStatus': StockStatus,
}

View File

@ -145,8 +145,10 @@ TEMPLATES = [
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.template.context_processors.i18n',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
'InvenTree.context.status_codes',
],
},
},

View File

@ -65,7 +65,7 @@ src="{% static 'img/blank_image.png' %}"
<tr>
<td><span class='fas fa-info'></span></td>
<td>{% trans "Status" %}</td>
<td>{% build_status build.status %}</td>
<td>{% build_status_label build.status %}</td>
</tr>
<tr>
<td><span class='fas fa-dollar-sign'></span></td>

View File

@ -40,7 +40,7 @@
<tr>
<td><span class='fas fa-info'></span></td>
<td>{% trans "Status" %}</td>
<td>{% build_status build.status %}</td>
<td>{% build_status_label build.status %}</td>
</tr>
{% if build.batch %}
<tr>

View File

@ -67,7 +67,7 @@ src="{% static 'img/blank_image.png' %}"
<tr>
<td><span class='fas fa-info'></span></td>
<td>{% trans "Order Status" %}</td>
<td>{% purchase_order_status order.status %}</td>
<td>{% purchase_order_status_label order.status %}</td>
</tr>
<tr>
<td><span class='fas fa-building'></span></td>

View File

@ -29,6 +29,7 @@ src="{% static 'img/blank_image.png' %}"
{% block page_data %}
<h3>{% trans "Sales Order" %}</h3>
<hr>
<h4>{{ order }}</h4>
@ -36,12 +37,15 @@ src="{% static 'img/blank_image.png' %}"
<div class='btn-row'>
<div class='btn-group action-buttons'>
<button type='button' class='btn btn-default' id='edit-order' title='Edit order information'>
<span class='fas fa-edit'></span>
<span class='fas fa-edit icon-green'></span>
</button>
<button type='button' class='btn btn-default' id='packing-list' title='{% trans "Packing List" %}'>
<span class='fas fa-clipboard-list'></span>
</button>
{% if order.is_pending %}
{% if order.status == SalesOrderStatus.PENDING %}
<button type='button' class='btn btn-default' id='ship-order' title='{% trans "Ship order" %}'>
<span class='fas fa-paper-plane icon-blue'></span>
</button>
<button type='button' class='btn btn-default' id='cancel-order' title='{% trans "Cancel order" %}'>
<span class='fas fa-times-circle icon-red'></span>
</button>
@ -62,7 +66,7 @@ src="{% static 'img/blank_image.png' %}"
<tr>
<td><span class='fas fa-info'></span></td>
<td>{% trans "Order Status" %}</td>
<td>{% sales_order_status order.status %}</td>
<td>{% sales_order_status_label order.status %}</td>
</tr>
<tr>
<td><span class='fas fa-building'></span></td>

View File

@ -6,9 +6,6 @@
{% load static %}
{% block details %}
{% include 'order/so_tabs.html' with tab='details' %}
<hr>
<h4>{% trans "Sales Order Items" %}</h4>

View File

@ -18,7 +18,7 @@
<td><a href="{% url 'build-detail' allocation.build.id %}">{{ allocation.build.title }}</a></td>
<td>{{ allocation.build.quantity }} &times <a href="{% url 'part-detail' allocation.build.part.id %}">{{ allocation.build.part.full_name }}</a></td>
<td>{{ allocation.quantity }}</td>
<td>{% build_status allocation.build.status %}</td>
<td>{% build_status_label allocation.build.status %}</td>
</tr>
{% endfor %}
</table>

View File

@ -11,35 +11,24 @@ register = template.Library()
@register.simple_tag
def purchase_order_status(key, *args, **kwargs):
def purchase_order_status_label(key, *args, **kwargs):
""" Render a PurchaseOrder status label """
return mark_safe(PurchaseOrderStatus.render(key))
@register.simple_tag
def sales_order_status(key, *args, **kwargs):
def sales_order_status_label(key, *args, **kwargs):
""" Render a SalesOrder status label """
return mark_safe(SalesOrderStatus.render(key))
@register.simple_tag
def stock_status(key, *args, **kwargs):
def stock_status_label(key, *args, **kwargs):
""" Render a StockItem status label """
return mark_safe(StockStatus.render(key))
@register.simple_tag
def build_status(key, *args, **kwargs):
def build_status_label(key, *args, **kwargs):
""" Render a Build status label """
return mark_safe(BuildStatus.render(key))
@register.simple_tag(takes_context=True)
def load_status_codes(context):
"""
Make the various StatusCodes available to the page context
"""
context['purchase_order_status_codes'] = PurchaseOrderStatus.list()
context['sales_order_status_codes'] = SalesOrderStatus.list()
context['stock_status_codes'] = StockStatus.list()
context['build_status_codes'] = BuildStatus.list()
# Need to return something as the result is rendered to the page
return ''

View File

@ -210,7 +210,7 @@ InvenTree | {% trans "Stock Item" %} - {{ item }}
<tr>
<td><span class='fas fa-info'></span></td>
<td>{% trans "Status" %}</td>
<td>{% stock_status item.status %}</td>
<td>{% stock_status_label item.status %}</td>
</tr>
</table>
{% endblock %}

View File

@ -1,14 +1,12 @@
{% load i18n %}
{% load status_codes %}
{% load_status_codes %}
<script type='text/javascript'>
{% include "status_codes.html" with label='stock' options=stock_status_codes %}
{% include "status_codes.html" with label='build' options=build_status_codes %}
{% include "status_codes.html" with label='purchaseOrder' options=purchase_order_status_codes %}
{% include "status_codes.html" with label='salesOrder' options=sales_order_status_codes %}
{% include "status_codes.html" with label='stock' options=StockStatus.list %}
{% include "status_codes.html" with label='build' options=BuildStatus.list %}
{% include "status_codes.html" with label='purchaseOrder' options=PurchaseOrderStatus.list %}
{% include "status_codes.html" with label='salesOrder' options=SalesOrderStatus.list %}
function getAvailableTableFilters(tableKey) {