Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Improve admin

Patryk Zawadzkicfc73374c603
diff --git a/saleor/checkout/templates/checkout/address.html b/saleor/checkout/templates/checkout/address.html
index d565ee27ea..4a192c40ba 100644
--- a/saleor/checkout/templates/checkout/address.html
+++ b/saleor/checkout/templates/checkout/address.html
@@ -16,7 +16,7 @@
<div class="panel-body">
<form method="post">
{% csrf_token %}
- {% include "userprofile/snippets/address-details.html" with address=entry.address %}
+ <address>{% include "userprofile/snippets/address-details.html" with address=entry.address %}</address>
{% for field in entry.form %}{{ field.as_hidden }}{% endfor %}
{% block extra_address_fields %}{% endblock %}
<div class="form-group">
diff --git a/saleor/checkout/templates/checkout/summary.html b/saleor/checkout/templates/checkout/summary.html
index 190a7e654e..ba619b72a9 100644
--- a/saleor/checkout/templates/checkout/summary.html
+++ b/saleor/checkout/templates/checkout/summary.html
@@ -4,7 +4,7 @@
{% block forms %}
<h3>{% trans "Billing address" %}</h3>
- {% include "userprofile/snippets/address-details.html" with address=checkout.billing_address %}
+ <address>{% include "userprofile/snippets/address-details.html" with address=checkout.billing_address %}</address>
<h3>{% trans "Order details" %}</h3>
diff --git a/saleor/order/admin.py b/saleor/order/admin.py
index 087ad933cf..3da87a21dd 100644
--- a/saleor/order/admin.py
+++ b/saleor/order/admin.py
@@ -1,12 +1,20 @@
-from django import forms
from django.contrib import admin
from django.contrib.admin.options import ModelAdmin
from django.forms.models import model_to_dict, BaseInlineFormSet
+from django.template.loader import render_to_string
+from django.utils.safestring import mark_safe
from .models import Order, OrderedItem
from ..payment.models import Payment
+def format_address(address):
+ address = render_to_string('userprofile/snippets/address-details.html',
+ {'address': address})
+ # avoid django's linebreaks breaking the result
+ return address.replace('\n', '')
+
+
class OrderModelAdmin(ModelAdmin):
def get_inline_instances(self, request, order=None):
@@ -49,17 +57,22 @@ class DeliveryInlineAdmin(admin.TabularInline):
self.delivery = delivery
delivery_class = delivery.__class__
if hasattr(delivery, 'address'):
- model_dict = model_to_dict(delivery.address, exclude='id')
- address = ', '.join(model_dict.values())
+ address = format_address(delivery.address)
self.verbose_name_plural = (
- 'ShippedDelivery (%s%s): %s' % (delivery.price.gross,
- delivery.price.currency,
- address))
+ mark_safe(
+ '%s: %s %s<br>%s' % (
+ delivery,
+ delivery.price.gross,
+ delivery.price.currency,
+ address)))
if hasattr(delivery, 'email'):
self.verbose_name_plural = (
- 'Digital delivery (%s%s): %s' % (delivery.price.gross,
- delivery.price.currency,
- delivery.email))
+ mark_safe(
+ '%s: %s %s<br>%s' % (
+ delivery,
+ delivery.price.gross,
+ delivery.price.currency,
+ delivery.email)))
super(DeliveryInlineAdmin, self).__init__(delivery_class, admin_site)
def get_formset(self, request, obj=None, **kwargs):
@@ -70,30 +83,20 @@ class DeliveryInlineAdmin(admin.TabularInline):
return formset
-class OrderAdminForm(forms.ModelForm):
-
- class Meta:
- model = Order
-
- total = forms.CharField(required=False)
-
- def __init__(self, *args, **kwargs):
- super(OrderAdminForm, self).__init__(*args, **kwargs)
- order = kwargs.get('instance')
- if order:
- self.fields['total'].initial = order.get_total().gross
-
-
class OrderAdmin(OrderModelAdmin):
inlines = [PaymentInlineAdmin]
exclude = ['token']
- readonly_fields = ['user', 'billing_address', 'total']
- form = OrderAdminForm
+ readonly_fields = ['customer', 'total']
list_display = ['__unicode__', 'status', 'created', 'user']
+ def customer(self, obj):
+ return format_address(obj.billing_address)
+ customer.allow_tags = True
+
def total(self, obj):
- return obj.get_total().gross
+ total = obj.get_total()
+ return '%s %s' % (total.gross, total.currency)
total.short_description = 'Total'
def has_add_permission(self, request, obj=None):
diff --git a/saleor/order/models.py b/saleor/order/models.py
index f994242eaf..5763ef150b 100644
--- a/saleor/order/models.py
+++ b/saleor/order/models.py
@@ -43,9 +43,12 @@ class Order(models.Model, ItemSet):
user = models.ForeignKey(
settings.AUTH_USER_MODEL, blank=True, null=True, related_name='orders',
verbose_name=pgettext_lazy('Order field', 'user'))
- tracking_client_id = models.CharField(max_length=36, blank=True)
- billing_address = models.ForeignKey(Address, related_name='+')
- anonymous_user_email = models.EmailField(blank=True, default='')
+ tracking_client_id = models.CharField(max_length=36, blank=True,
+ editable=False)
+ billing_address = models.ForeignKey(Address, related_name='+',
+ editable=False)
+ anonymous_user_email = models.EmailField(blank=True, default='',
+ editable=False)
token = models.CharField(
pgettext_lazy('Order field', 'token'),
max_length=36, blank=True, default='')
diff --git a/saleor/order/templates/order/details.html b/saleor/order/templates/order/details.html
index 48b437cff6..aba3a587d3 100644
--- a/saleor/order/templates/order/details.html
+++ b/saleor/order/templates/order/details.html
@@ -23,7 +23,7 @@
{% if order.user == user %}
<h3>{% trans "Billing address" %}</h3>
- {% include "userprofile/snippets/address-details.html" with address=order.billing_address %}
+ <address>{% include "userprofile/snippets/address-details.html" with address=order.billing_address %}</address>
{% endif %}
<h3>{% trans "Order details" %}</h3>
<p>{% trans "Status" %}: <span class="label label-default">{{ order.get_status_display }}</span></p>
diff --git a/saleor/userprofile/templates/userprofile/address-delete.html b/saleor/userprofile/templates/userprofile/address-delete.html
index 052b6b5a84..2cfb8ac441 100644
--- a/saleor/userprofile/templates/userprofile/address-delete.html
+++ b/saleor/userprofile/templates/userprofile/address-delete.html
@@ -11,7 +11,7 @@
{% block content %}
<h2>{% trans "Are you sure you want to delete the following address?" %}</h2>
- {% include "userprofile/snippets/address-details.html" with address=object.address %}
+ <address>{% include "userprofile/snippets/address-details.html" with address=object.address %}</address>
<form action="." method="post">
{% csrf_token %}
<button type="submit" class="btn btn-danger">{% trans "Delete" %}</button>
diff --git a/saleor/userprofile/templates/userprofile/snippets/address-details.html b/saleor/userprofile/templates/userprofile/snippets/address-details.html
index 3de6c6f574..e4383b8cb7 100644
--- a/saleor/userprofile/templates/userprofile/snippets/address-details.html
+++ b/saleor/userprofile/templates/userprofile/snippets/address-details.html
@@ -1,10 +1,8 @@
-<address>
- <strong>{{ address.first_name }} {{ address.last_name }}</strong><br>
- {{ address.street_address_1 }}<br>
- {% if address.street_address_2 %}
- {{ address.street_address_2 }}<br>
- {% endif %}
- {{ address.postal_code }} {{ address.city }}<br>
- {% if address.country_area %}{{ address.country_area }}, {% endif %}{{ address.get_country_display }}<br>
- {{ address.phone }}
-</address>
+<strong>{{ address.first_name }} {{ address.last_name }}</strong><br>
+{{ address.street_address_1 }}<br>
+{% if address.street_address_2 %}
+ {{ address.street_address_2 }}<br>
+{% endif %}
+{{ address.postal_code }} {{ address.city }}<br>
+{% if address.country_area %}{{ address.country_area }}, {% endif %}{{ address.get_country_display }}<br>
+{{ address.phone }}