Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Render statuses using template tag
Marcin Gębala72c73debda2b
diff --git a/saleor/core/templates/status_label.html b/saleor/core/templates/status_label.htmlnew file mode 100644index 0000000000..6e584b7725--- /dev/null+++ b/saleor/core/templates/status_label.html@@ -0,0 +1 @@+<span class="label label-{{ label_cls }}">{{ status }}</span>\ No newline at end of filediff --git a/saleor/core/templatetags/status.py b/saleor/core/templatetags/status.pynew file mode 100644index 0000000000..4e4f5dc559--- /dev/null+++ b/saleor/core/templatetags/status.py@@ -0,0 +1,18 @@+from django.template import Library++register = Library()+++ERROR = ['error', 'reject', 'rejected']+SUCCESS = ['accept', 'confirmed', 'fully-paid', 'shipped', 'refunded']++[email protected]_tag('status_label.html')+def render_status(status, status_display=None):+ if status in ERROR:+ label_cls = 'danger'+ elif status in SUCCESS:+ label_cls = 'success'+ else:+ label_cls = 'default'+ return {'label_cls': label_cls, 'status': status_display or status}diff --git a/saleor/dashboard/templates/dashboard/customer/detail.html b/saleor/dashboard/templates/dashboard/customer/detail.htmlindex 51c44c7938..9247317ad7 100644--- a/saleor/dashboard/templates/dashboard/customer/detail.html+++ b/saleor/dashboard/templates/dashboard/customer/detail.html@@ -2,6 +2,7 @@{% load prices_i18n %}{% load i18n %}{% load bootstrap %}+{% load status %}{% block title %}Order details{% endblock %}@@ -32,8 +33,8 @@<tr><td><a href="{% url 'dashboard:order-details' pk=order.pk %}">{{ order }}</a></td><td>{{ order.created }}</td>- <td>{% include 'dashboard/includes/_status_label.html' with status=order.get_last_payment_status status_display=order.get_last_payment_status_display %}</td>- <td>{% include 'dashboard/includes/_status_label.html' with status=order.status status_display=order.get_status_display %}</td>+ <td>{% render_status order.get_last_payment_status order.get_last_payment_status_display %}</td>+ <td>{% render_status order.status order.get_status_display %}</td><td>{% gross order.get_total %}</td></tr>{% endfor %}diff --git a/saleor/dashboard/templates/dashboard/includes/_status_label.html b/saleor/dashboard/templates/dashboard/includes/_status_label.htmldeleted file mode 100644index 8206718aa1..0000000000--- a/saleor/dashboard/templates/dashboard/includes/_status_label.html+++ /dev/null@@ -1,9 +0,0 @@-{% with errors='error reject rejected' successes='accept confirmed fully-paid shipped refunded' %}- {% if status in errors.split %}- <span class="label label-danger">{{ status_display }}</span>- {% elif status in successes.split %}- <span class="label label-success">{{ status_display }}</span>- {% else %}- <span class="label label-default">{{ status_display }}</span>- {% endif %}-{% endwith %}diff --git a/saleor/dashboard/templates/dashboard/order/detail.html b/saleor/dashboard/templates/dashboard/order/detail.htmlindex e7285a746b..0dde3fda51 100644--- a/saleor/dashboard/templates/dashboard/order/detail.html+++ b/saleor/dashboard/templates/dashboard/order/detail.html@@ -2,6 +2,7 @@{% load prices_i18n %}{% load i18n %}{% load bootstrap %}+{% load status %}{% block title %}Order details{% endblock %}@@ -19,8 +20,9 @@<table class="table table-condensed"><thead><tr>- <th class="col-sm-1">Delivery group #{{ group.pk }}</th>- <th>{% include 'dashboard/includes/_status_label.html' with status=group.status status_display=group.status %}</th>+ <th colspan=6>+ <span>Delivery group #{{ group.pk }} {% render_status group.status %}</span>+ </th></tr><tr><th class="col-sm-2">{% trans "Name" %}</th>@@ -101,7 +103,7 @@{% for event in order.history.all %}<tr><td>{{ event.date }}</td>- <td>{% include 'dashboard/includes/_status_label.html' with status=event.status status_display=event.get_status_display %}</td>+ <td>{% render_status event.status event.get_status_display %}</td><td>{{ event.user|default:"-" }}</td><td>{{ event.comment|default:"-" }}</td></tr>@@ -122,7 +124,7 @@{% for payment in order.payments.all %}<tr><td>{{ payment.created }}</td>- <td>{% include 'dashboard/includes/_status_label.html' with status=payment.status status_display=payment.get_status_display %}</td>+ <td>{% render_status payment.status payment.get_status_display %}</td><td><a href="{% url "dashboard:payment-details" pk=payment.pk %}">Details</a></td></tr>{% endfor %}@@ -169,8 +171,8 @@</div><div class="panel-body"><p>Order date: {{ order.created }}</p>- <p>Order status: {% include 'dashboard/includes/_status_label.html' with status=order.status status_display=order.get_status_display %}</p>- <p>Payment status: {% include 'dashboard/includes/_status_label.html' with status=order.get_last_payment_status status_display=order.get_last_payment_status_display %}</p>+ <p>Order status: {% render_status order.status order.get_status_display %}</p>+ <p>Payment status: {% render_status payment.status payment.get_status_display %}</p><p>Total: {{ payment.total }} {{ payment.currency }}</p>{% if payment %}<p>Captured: {{ payment.captured_amount }} {{ payment.currency }}</p>diff --git a/saleor/dashboard/templates/dashboard/order/list.html b/saleor/dashboard/templates/dashboard/order/list.htmlindex 15f7c34bdb..82174721be 100644--- a/saleor/dashboard/templates/dashboard/order/list.html+++ b/saleor/dashboard/templates/dashboard/order/list.html@@ -1,6 +1,7 @@{% extends "dashboard/base.html" %}{% load i18n %}{% load prices_i18n %}+{% load status %}{% block title %}{% trans "All orders" %}{% endblock %}@@ -24,7 +25,7 @@</td><td>{{ order.user|default:"Anonymous" }}</td><td>{% gross order.get_total %}</td>- <td>{% include 'dashboard/includes/_status_label.html' with status=order.status status_display=order.get_status_display %}</td>+ <td>{% render_status order.status order.get_status_display %}</td></tr>{% endfor %}</tbody>diff --git a/saleor/dashboard/templates/dashboard/payments/detail.html b/saleor/dashboard/templates/dashboard/payments/detail.htmlindex b5e67aa52f..2dc33b5103 100644--- a/saleor/dashboard/templates/dashboard/payments/detail.html+++ b/saleor/dashboard/templates/dashboard/payments/detail.html@@ -2,6 +2,7 @@{% load prices_i18n %}{% load i18n %}{% load bootstrap %}+{% load status %}{% block title %}Payment details{% endblock %}@@ -15,8 +16,8 @@<span class="panel-title">Payment details</span></div><div class="panel-body">- <p>Status: {% include 'dashboard/includes/_status_label.html' with status=payment.status status_display=payment.get_status_display %}</p>- <p>Fraud status: {% include 'dashboard/includes/_status_label.html' with status=payment.fraud_status status_display=payment.get_fraud_status_display %}</p>+ <p>Status: {% render_status payment.status payment.get_status_display %}</p>+ <p>Fraud status: {% render_status payment.fraud_status payment.get_fraud_status_display %}</p><p>Amount: {{ payment.total }} {{ payment.currency }}</p><p>Captured amount: {{ payment.captured_amount }} {{ payment.currency }}</p><p>Gateway: {{ payment.variant }}</p>diff --git a/saleor/dashboard/templates/dashboard/payments/list.html b/saleor/dashboard/templates/dashboard/payments/list.htmlindex 9a0ab9f925..6e2e8208a3 100644--- a/saleor/dashboard/templates/dashboard/payments/list.html+++ b/saleor/dashboard/templates/dashboard/payments/list.html@@ -1,6 +1,7 @@{% extends "dashboard/base.html" %}{% load i18n %}{% load prices_i18n %}+{% load status %}{% block title %}{% trans "All orders" %}{% endblock %}@@ -31,7 +32,7 @@<th>{{ payment.created }}</th><td>{{ payment.order.user|default:"Anonymous" }}</td><td>{{ payment.total }}</td>- <td>{% include 'dashboard/includes/_status_label.html' with status=payment.status status_display=payment.get_status_display %}</td>+ <td>{% render_status payment.status payment.get_status_display %}</td><td>{{ payment.captured_amount }}</td>