mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
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:
parent
2c9b112562
commit
b45fec221c
19
InvenTree/InvenTree/context.py
Normal file
19
InvenTree/InvenTree/context.py
Normal 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,
|
||||
}
|
@ -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',
|
||||
],
|
||||
},
|
||||
},
|
||||
|
@ -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>
|
||||
|
@ -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>
|
||||
|
@ -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>
|
||||
|
@ -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>
|
||||
|
@ -6,9 +6,6 @@
|
||||
{% load static %}
|
||||
|
||||
{% block details %}
|
||||
|
||||
{% include 'order/so_tabs.html' with tab='details' %}
|
||||
|
||||
<hr>
|
||||
|
||||
<h4>{% trans "Sales Order Items" %}</h4>
|
||||
|
@ -18,7 +18,7 @@
|
||||
<td><a href="{% url 'build-detail' allocation.build.id %}">{{ allocation.build.title }}</a></td>
|
||||
<td>{{ allocation.build.quantity }} × <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>
|
||||
|
@ -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 ''
|
||||
|
@ -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 %}
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user