Skip to content

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

Edit order addresses

Marcin Gębaladabb7fbb420f
diff --git a/saleor/dashboard/order/urls.py b/saleor/dashboard/order/urls.py
index ee8070a686..ab5f8fc688 100644
--- a/saleor/dashboard/order/urls.py
+++ b/saleor/dashboard/order/urls.py
@@ -6,5 +6,8 @@ urlpatterns = patterns('',
name='orders'),
url(r'^(?P<pk>[0-9]+)$',
views.OrderDetails.as_view(),
- name='order-details')
-)
+ name='order-details'),
+ url(r'^(?P<order_pk>[0-9]+)/address/(?P<pk>[0-9]+)$',
+ views.AddressView.as_view(),
+ name='address-edit')
+ )
diff --git a/saleor/dashboard/order/views.py b/saleor/dashboard/order/views.py
index 740da5215a..89e80a923c 100644
--- a/saleor/dashboard/order/views.py
+++ b/saleor/dashboard/order/views.py
@@ -1,7 +1,9 @@
from django.contrib import messages
from django.utils.translation import ugettext_lazy as _
-from django.views.generic import ListView, DetailView
-from ...order.models import Order
+from django.views.generic import ListView, DetailView, UpdateView
+from django.shortcuts import redirect
+from ...order.models import Order, Address
+from ...userprofile.forms import AddressForm
from ..views import StaffMemberOnlyMixin, FilterByStatusMixin
from .forms import OrderNoteForm
@@ -59,3 +61,14 @@ class OrderDetails(StaffMemberOnlyMixin, DetailView):
messages.error(self.request, _('Form has errors'))
self.form_instance = form
return self.get(*args, **kwargs)
+
+
+class AddressView(StaffMemberOnlyMixin, UpdateView):
+ model = Address
+ template_name = 'dashboard/customer/address-edit.html'
+ form_class = AddressForm
+
+ def form_valid(self, form):
+ self.object = form.save()
+ order_pk = self.kwargs.get('order_pk')
+ return redirect('dashboard:order-details', pk=order_pk)
diff --git a/saleor/dashboard/templates/dashboard/customer/address-edit.html b/saleor/dashboard/templates/dashboard/customer/address-edit.html
new file mode 100644
index 0000000000..52398858ca
--- /dev/null
+++ b/saleor/dashboard/templates/dashboard/customer/address-edit.html
@@ -0,0 +1,24 @@
+{% extends "dashboard/base.html" %}
+
+{% block title %}Edit address{% endblock %}
+
+{% load as_vertical_form from bootstrap %}
+
+{% block content %}
+<div class="row">
+ <h1 class="page-header">Edit address</h1>
+
+ <div class="col-md-6">
+ <form method="post">
+ {% csrf_token %}
+ <fieldset>
+ {{ form|as_vertical_form }}
+ </fieldset>
+ <div class="form-group">
+ <button type="submit" class="btn btn-primary">Save</button>
+ </div>
+ </form>
+ </div>
+
+</div>
+{% endblock content %}
diff --git a/saleor/dashboard/templates/dashboard/order/detail.html b/saleor/dashboard/templates/dashboard/order/detail.html
index 4cc1d9d31c..67e741f050 100644
--- a/saleor/dashboard/templates/dashboard/order/detail.html
+++ b/saleor/dashboard/templates/dashboard/order/detail.html
@@ -96,23 +96,25 @@
</div>
</div>
<div class="box">
+ {% with order.billing_address as address %}
<div class="box-header">
{% if addresses_equal %}
<span>Billing & Delivery address</span>
{% else %}
<span>Billing address</span>
{% endif %}
+ <span class="pull-right"><a href="{% url "dashboard:address-edit" pk=address.pk order_pk=order.pk %}"><i class="glyphicon glyphicon-cog"></i> Edit</a></span>
</div>
- {% with order.billing_address as address %}
- {% include 'dashboard/includes/_address.html' with address=address only %}
+ {% include 'dashboard/includes/_address.html' with address=address only %}
{% endwith %}
</div>
{% if not addresses_equal %}
<div class="box">
- <div class="box-header">
- <span>Shipping address</span>
- </div>
{% with view.get_delivery_info as delivery %}
+ <div class="box-header">
+ <span>Shipping address</span>
+ <span class="pull-right"><a href="{% url "dashboard:address-edit" pk=delivery.address.pk order_pk=order.pk %}"><i class="glyphicon glyphicon-cog"></i> Edit</a></span>
+ </div>
{% include 'dashboard/includes/_address.html' with address=delivery.address only %}
{% endwith %}
</div>