Skip to content

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

Add shipping method detail view

Mira Szewczyk48db148c248e
diff --git a/saleor/dashboard/shipping/urls.py b/saleor/dashboard/shipping/urls.py
index 45727dfe2c..f931a22c04 100644
--- a/saleor/dashboard/shipping/urls.py
+++ b/saleor/dashboard/shipping/urls.py
@@ -5,7 +5,10 @@ from . import views
urlpatterns = [
url(r'^$', views.shipping_method_list, name='shipping-methods'),
url(r'^add/$', views.shipping_method_add, name='shipping-method-add'),
- url(r'^(?P<pk>\d+)/$', views.shipping_method_detail, name='shipping-method-detail'),
+ url(r'^(?P<pk>\d+)/update/$', views.shipping_method_update,
+ name='shipping-method-update'),
+ url(r'^(?P<pk>\d+)/$', views.shipping_method_detail,
+ name='shipping-method-detail'),
url(r'^(?P<pk>\d+)/delete/$',
views.shipping_method_delete, name='shipping-method-delete'),
]
diff --git a/saleor/dashboard/shipping/views.py b/saleor/dashboard/shipping/views.py
index b369b35437..9bb7393122 100644
--- a/saleor/dashboard/shipping/views.py
+++ b/saleor/dashboard/shipping/views.py
@@ -30,7 +30,8 @@ def shipping_method_edit(request, method):
'Dashboard message', '%(shipping_method_name)s method saved') % {
'shipping_method_name': shipping_method}
messages.success(request, msg)
- return redirect('dashboard:shipping-methods')
+ return redirect(
+ 'dashboard:shipping-method-detail', pk=shipping_method.pk)
ctx = {'shipping_method_form': form,
'price_per_country_formset': formset, 'shipping_method': method}
return TemplateResponse(request, 'dashboard/shipping/method_form.html', ctx)
@@ -43,11 +44,22 @@ def shipping_method_add(request):
@staff_member_required
-def shipping_method_detail(request, pk):
+def shipping_method_update(request, pk):
method = get_object_or_404(ShippingMethod, pk=pk)
return shipping_method_edit(request, method)
+@staff_member_required
+def shipping_method_detail(request, pk):
+ shipping_methods = ShippingMethod.objects.prefetch_related(
+ 'price_per_country').all()
+ method = get_object_or_404(shipping_methods, pk=pk)
+ method_countries = method.price_per_country.all()
+ ctx = {'shipping_method': method, 'method_countries': method_countries}
+ return TemplateResponse(
+ request, 'dashboard/shipping/method_detail.html', ctx)
+
+
@staff_member_required
def shipping_method_delete(request, pk):
shipping_method = get_object_or_404(ShippingMethod, pk=pk)
diff --git a/templates/dashboard/shipping/method_detail.html b/templates/dashboard/shipping/method_detail.html
new file mode 100644
index 0000000000..75721ced56
--- /dev/null
+++ b/templates/dashboard/shipping/method_detail.html
@@ -0,0 +1,120 @@
+{% extends 'dashboard/base.html' %}
+
+{% load i18n %}
+{% load prices_i18n %}
+
+{% block title %}
+ {% trans "Shipping methods" context "Shipping method form page title" %}
+ - {{ shipping_method }} - {{ block.super }}
+{% endblock %}
+
+{% block body_class %}body-shipping-methods{% endblock %}
+
+{% block menu_delivery_class %}active{% endblock %}
+
+{% block menu_shipping_class %} active{% endblock %}
+
+{% block breadcrumbs %}
+ <ul class="breadcrumbs breadcrumbs--history">
+ <li>
+ <a href="{% url "dashboard:shipping-methods" %}">
+ {% trans "Shipping methods" context "Shipping method form breadcrumbs" %}
+ </a>
+ </li>
+ <li class="back-mobile">
+ <a href="{% url 'dashboard:shipping-methods' %}"><i class="material-icons">arrow_back</i></a>
+ </li>
+ <li>
+ <span class="breadcrumbs--elipsed-item">
+ {{ shipping_method }}
+ </span>
+ </li>
+ </ul>
+{% endblock %}
+
+{% block header_extra %}
+ <a class="dropdown-button right" href="#" data-activates="context-menu" data-constrainwidth="false">
+ <i class="material-icons">more_vert</i>
+ </a>
+ <ul id="context-menu" class="dropdown-content">
+ <li>
+ <a href="{% url "dashboard:shipping-method-update" shipping_method.pk %}">
+ {% trans "Edit shipping method" context "Shipping method action" %}
+ </a>
+ </li>
+ <li>
+ <a href="{% url "dashboard:shipping-method-delete" shipping_method.pk %}">
+ {% trans "Delete shipping method" context "Shipping method action" %}
+ </a>
+ </li>
+ </ul>
+{% endblock %}
+
+
+{% block content %}
+ <div class="row">
+ <div class="col m12 l9">
+ <div class="card">
+ <div class="card-content">
+ <span class="card-title">
+ {% trans "Shipping method" context "Shipping method title" %}
+ </span>
+ <div class="row">
+ <div class="col s12 m4 l12">
+ <h5>
+ {% trans "Name" context "Shipping method field" %}
+ </h5>
+ <p>
+ {{ shipping_method.name }}
+ </p>
+ </div>
+ {% if shipping_method.description %}
+ <div class="col s12 m4 l12">
+ <h5>
+ {% trans "Description" context "Shipping method field" %}
+ </h5>
+ <p>
+ {{ shipping_method.description }}
+ </p>
+ </div>
+ {% endif %}
+ </div>
+ </div>
+ </div>
+ </div>
+
+ <div class="col m12 l9">
+ <div class="card">
+ <div class="data-table-header">
+ <h5 class="data-table-title">
+ {% trans "Price per country" %}
+ </h5>
+ </div>
+ <div class="data-table-container">
+ <table class="bordered highlight responsive data-table">
+ <thead>
+ <tr>
+ <th>
+ {% trans "Country" %}
+ </th>
+ <th>{% trans "Price" %}</th>
+ </tr>
+ </thead>
+ <tbody>
+ {% for price in method_countries %}
+ <tr>
+ <td>{{ price.get_country_code_display }}</td>
+ <td>{% gross price.price %}</td>
+ </tr>
+ {% empty %}
+ <tr>
+ <td colspan="2">{% trans "No shippment prices" %}</td>
+ </tr>
+ {% endfor %}
+ </tbody>
+ </table>
+ </div>
+ </div>
+ </div>
+ </div>
+{% endblock %}
\ No newline at end of file
diff --git a/templates/dashboard/shipping/method_form.html b/templates/dashboard/shipping/method_form.html
index 6a246d610f..7de5070950 100644
--- a/templates/dashboard/shipping/method_form.html
+++ b/templates/dashboard/shipping/method_form.html
@@ -52,21 +52,6 @@
</ul>
{% endblock %}
-{% block header_extra %}
- {% if shipping_method.pk %}
- <a class="dropdown-button right" href="#" data-activates="context-menu" data-constrainwidth="false">
- <svg data-src="{% static "dashboard/images/more_vert.svg" %}" height="24" width="24" />
- </a>
- <ul id="context-menu" class="dropdown-content">
- <li>
- <a href="{% url 'dashboard:shipping-method-delete' pk=shipping_method.pk %}">
- {% trans "Delete shipping method" context "Shipping method form action" %}
- </a>
- </li>
- </ul>
- {% endif %}
-{% endblock %}
-
{% block menu_shipping_class %} active{% endblock %}
{% block content %}
@@ -80,9 +65,7 @@
<div class="row">
{{ shipping_method_form|materializecss }}
</div>
- <h5 class="card-title">
- {% trans "Price per country" context "Shipping method form text" %}
- </h5>
+ <h5 class="card-title">{% trans "Price per country" context "Shipping method form text" %}</h5>
</div>
<div class="formset-table-container">
<table class="formset-table">
@@ -101,32 +84,33 @@
</thead>
<tbody>
{% for form in price_per_country_formset %}
- <tr>
- <td>
- {% for hidden in form.hidden_fields %}
- {{ hidden }}
- {% endfor %}
- {{ form.country_code|materializecss:"input-field s12" }}
- {% if form.non_field_errors %}
- {% for error in form.non_field_errors %}
- <p class="help-block materialize-red-text">{{ error }}</p>
+ <tr>
+ <td>
+ {% for hidden in form.hidden_fields %}
+ {{ hidden }}
{% endfor %}
- {% endif %}
- </td>
- <td>
- {{ form.price|materializecss }}
- </td>
- <td>
- {{ form.DELETE|materializecss }}
- </td>
- </tr>
+ {{ form.country_code|materializecss:"input-field s12" }}
+ {% if form.non_field_errors %}
+ {% for error in form.non_field_errors %}
+ <p class="help-block materialize-red-text">{{ error }}</p>
+ {% endfor %}
+ {% endif %}
+ </td>
+ <td>
+ {{ form.price|materializecss }}
+ </td>
+ <td>
+ {{ form.DELETE|materializecss }}
+ </td>
+ </tr>
{% endfor %}
</tbody>
</table>
</div>
+
<div class="card-action right-align">
{% if shipping_method.pk %}
- <a href="{% url 'dashboard:shipping-methods' %}" class="btn btn-flat">
+ <a href="{% url 'dashboard:shipping-method-detail' shipping_method.pk %}" class="btn btn-flat">
{% trans "Cancel" context "Dashboard cancel action" %}
</a>
<button type="submit" class="btn waves-effect waves-light">