Skip to content

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

Drop bulk actions; fix redirect urls to product details

Marcin Gębala9f1177656cac
diff --git a/saleor/dashboard/product/api.py b/saleor/dashboard/product/api.py
index f475a33a5d..e911df667e 100644
--- a/saleor/dashboard/product/api.py
+++ b/saleor/dashboard/product/api.py
@@ -55,7 +55,7 @@ def upload_image(request, product_pk):
serializer = UploadImageSerializer(data=request.data)
if serializer.is_valid():
image = serializer.save(product=product)
- return Response(ProductImageSerializer(image).data,
- status=status.HTTP_200_OK)
+ return Response(
+ ProductImageSerializer(image).data, status=status.HTTP_200_OK)
else:
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
diff --git a/saleor/dashboard/product/urls.py b/saleor/dashboard/product/urls.py
index 4ef08d9160..7334c929c4 100644
--- a/saleor/dashboard/product/urls.py
+++ b/saleor/dashboard/product/urls.py
@@ -37,17 +37,13 @@ urlpatterns = [
views.variant_delete, name='variant-delete'),
url(r'^(?P<product_pk>[0-9]+)/variants/(?P<variant_pk>[0-9]+)/images/$',
views.variant_images, name='variant-images'),
- url(r'^(?P<product_pk>[0-9]+)/variants/bulk_delete/',
- views.variants_bulk_delete, name='variant-bulk-delete'),
url(r'^(?P<product_pk>[0-9]+)/variants/(?P<variant_pk>[0-9]+)/stock/add/$',
views.stock_edit, name='variant-stock-add'),
url(r'^(?P<product_pk>[0-9]+)/variants/(?P<variant_pk>[0-9]+)/stock/(?P<stock_pk>[0-9]+)/$',
views.stock_edit, name='variant-stock-update'),
- url(r'^(?P<product_pk>[0-9]+)/stock/(?P<stock_pk>[0-9]+)/delete/$',
- views.stock_delete, name='product-stock-delete'),
- url(r'^(?P<product_pk>[0-9]+)/stock/bulk_delete/',
- views.stock_bulk_delete, name='stock-bulk-delete'),
+ url(r'^(?P<product_pk>[0-9]+)/variants/(?P<variant_pk>[0-9]+)/stock/(?P<stock_pk>[0-9]+)/delete/$',
+ views.stock_delete, name='variant-stock-delete'),
url(r'^(?P<product_pk>[0-9]+)/images/$', views.product_images,
name='product-image-list'),
@@ -57,9 +53,9 @@ urlpatterns = [
views.product_image_edit, name='product-image-add'),
url(r'^(?P<product_pk>[0-9]+)/images/(?P<img_pk>[0-9]+)/delete/$',
views.product_image_delete, name='product-image-delete'),
- url('^(?P<product_pk>[0-9]+)/images/reorder/$',
+ url(r'^(?P<product_pk>[0-9]+)/images/reorder/$',
api.reorder_product_images, name='product-images-reorder'),
- url('^(?P<product_pk>[0-9]+)/images/upload/$',
+ url(r'^(?P<product_pk>[0-9]+)/images/upload/$',
api.upload_image, name='product-images-upload'),
url(r'attributes/$',
diff --git a/saleor/dashboard/product/views.py b/saleor/dashboard/product/views.py
index dc33cee7c8..580db7edc5 100644
--- a/saleor/dashboard/product/views.py
+++ b/saleor/dashboard/product/views.py
@@ -160,22 +160,13 @@ def product_toggle_is_published(request, pk):
@staff_member_required
def product_edit(request, pk):
product = get_object_or_404(
- Product.objects.prefetch_related(
- 'images', 'variants'), pk=pk)
- edit_variant = not product.product_class.has_variants
- attributes = product.product_class.variant_attributes.prefetch_related(
- 'values')
- images = product.images.all()
- variants = product.variants.all()
- stock_items = Stock.objects.filter(
- variant__in=variants).select_related('variant', 'location')
+ Product.objects.prefetch_related('variants'), pk=pk)
+ edit_variant = not product.product_class.has_variants
form = forms.ProductForm(request.POST or None, instance=product)
- variants_delete_form = forms.VariantBulkDeleteForm()
- stock_delete_form = forms.StockBulkDeleteForm()
if edit_variant:
- variant = variants.first()
+ variant = product.variants.first()
variant_form = forms.ProductVariantForm(
request.POST or None, instance=variant, prefix='variant')
variant_errors = not variant_form.is_valid()
@@ -189,11 +180,8 @@ def product_edit(request, pk):
'Dashboard message', 'Updated product %s') % product
messages.success(request, msg)
return redirect('dashboard:product-detail', pk=product.pk)
- ctx = {'attributes': attributes, 'images': images, 'product_form': form,
- 'product': product, 'stock_delete_form': stock_delete_form,
- 'stock_items': stock_items, 'variants': variants,
- 'variants_delete_form': variants_delete_form,
- 'variant_form': variant_form}
+ ctx = {
+ 'product': product, 'product_form': form, 'variant_form': variant_form}
return TemplateResponse(
request, 'dashboard/product/product_form.html', ctx)
@@ -234,34 +222,20 @@ def stock_edit(request, product_pk, variant_pk, stock_pk=None):
@staff_member_required
-def stock_delete(request, product_pk, stock_pk):
+def stock_delete(request, product_pk, variant_pk, stock_pk):
product = get_object_or_404(Product, pk=product_pk)
+ variant = get_object_or_404(product.variants, pk=variant_pk)
stock = get_object_or_404(Stock, pk=stock_pk)
if request.method == 'POST':
stock.delete()
messages.success(
request, pgettext_lazy('Dashboard message', 'Deleted stock'))
- success_url = request.POST['success_url']
- if is_safe_url(success_url, allowed_hosts=request.get_host()):
- return redirect(success_url)
- ctx = {'product': product, 'stock': stock}
+ return redirect(
+ 'dashboard:variant-details', product_pk=product.pk,
+ variant_pk=variant.pk)
+ ctx = {'product': product, 'stock': stock, 'variant': variant.pk}
return TemplateResponse(
- request, 'dashboard/product/stock_confirm_delete.html', ctx)
-
-
-@staff_member_required
-@require_http_methods(['POST'])
-def stock_bulk_delete(request, product_pk):
- product = get_object_or_404(Product, pk=product_pk)
- form = forms.StockBulkDeleteForm(request.POST)
- if form.is_valid():
- form.delete()
- success_url = request.POST['success_url']
- messages.success(
- request, pgettext_lazy('Dashboard message', 'Deleted stock'))
- if is_safe_url(success_url, allowed_hosts=request.get_host()):
- return redirect(success_url)
- return redirect('dashboard:product-update', pk=product.pk)
+ request, 'dashboard/product/modal_stock_confirm_delete.html', ctx)
@staff_member_required
@@ -280,7 +254,6 @@ def product_image_edit(request, product_pk, img_pk=None):
product_image = get_object_or_404(product.images, pk=img_pk)
else:
product_image = ProductImage(product=product)
- show_variants = product.product_class.has_variants
form = forms.ProductImageForm(request.POST or None, request.FILES or None,
instance=product_image)
if form.is_valid():
@@ -297,8 +270,7 @@ def product_image_edit(request, product_pk, img_pk=None):
success_url = request.POST['success_url']
if is_safe_url(success_url, allowed_hosts=request.get_host()):
return redirect(success_url)
- ctx = {'form': form, 'product': product, 'product_image': product_image,
- 'show_variants': show_variants}
+ ctx = {'form': form, 'product': product, 'product_image': product_image}
return TemplateResponse(
request, 'dashboard/product/product_image_form.html', ctx)
@@ -314,9 +286,7 @@ def product_image_delete(request, product_pk, img_pk):
pgettext_lazy(
'Dashboard message',
'Deleted image %s') % product_image.image.name)
- success_url = request.POST['success_url']
- if is_safe_url(success_url, allowed_hosts=request.get_host()):
- return redirect(success_url)
+ return redirect('dashboard:product-image-list', product_pk=product.pk)
ctx = {'product': product, 'product_image': product_image}
return TemplateResponse(
request,
@@ -400,22 +370,6 @@ def variant_delete(request, product_pk, variant_pk):
'dashboard/product/modal_variant_confirm_delete.html', ctx)
-@staff_member_required
-@require_http_methods(['POST'])
-def variants_bulk_delete(request, product_pk):
- product = get_object_or_404(Product, pk=product_pk)
- form = forms.VariantBulkDeleteForm(request.POST)
- if form.is_valid():
- form.delete()
- success_url = request.POST['success_url']
- messages.success(
- request,
- pgettext_lazy('Dashboard message', 'Deleted variants'))
- if is_safe_url(success_url, allowed_hosts=request.get_host()):
- return redirect(success_url)
- return redirect('dashboard:product-update', pk=product.pk)
-
-
@staff_member_required
def attribute_list(request):
attributes = [
diff --git a/templates/dashboard/index.html b/templates/dashboard/index.html
index bf7963254d..b2e0914665 100644
--- a/templates/dashboard/index.html
+++ b/templates/dashboard/index.html
@@ -100,7 +100,7 @@
</thead>
<tbody>
{% for product in low_stock %}
- <tr data-action-go="{% url "dashboard:product-update" pk=product.pk %}#stock">
+ <tr data-action-go="{% url "dashboard:product-detail" pk=product.pk %}#stock">
<td>
{{ product }}
</td>
diff --git a/templates/dashboard/product/images.html b/templates/dashboard/product/images.html
index c010e90aa0..8cab7ada09 100644
--- a/templates/dashboard/product/images.html
+++ b/templates/dashboard/product/images.html
@@ -39,7 +39,6 @@
<form action="{% url 'dashboard:product-images-upload' product_pk=product.pk %}" class="dropzone" id="product-image-form" novalidate>
<div class="dz-message"></div>
{% csrf_token %}
- <input type="hidden" name="success_url" value="{% url 'dashboard:product-update' pk=product.pk %}#images">
<div class="row">
{% if images %}
<ul class="product-gallery" id="product-gallery" data-post-url="{% url 'dashboard:product-images-reorder' product_pk=product.pk %}">
diff --git a/templates/dashboard/product/modal_stock_confirm_delete.html b/templates/dashboard/product/modal_stock_confirm_delete.html
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/templates/dashboard/product/product_confirm_delete.html b/templates/dashboard/product/product_confirm_delete.html
deleted file mode 100644
index 7ffa3a936e..0000000000
--- a/templates/dashboard/product/product_confirm_delete.html
+++ /dev/null
@@ -1,65 +0,0 @@
-{% extends "dashboard/base.html" %}
-{% load i18n %}
-{% load prices_i18n %}
-{% load staticfiles %}
-{% load product_first_image from product_images %}
-
-{% block title %}
- {% trans "Delete" context "Dashboard delete action" %} {{ product }} - {{ block.super }}
-{% endblock %}
-
-{% block body_class %}body-store body-products{% endblock %}
-
-{% block header_menu %}
- {% url "dashboard:product-update" pk=product.pk as url %}
- {% include "dashboard/includes/_back-link.html" with url=url %}
-{% endblock %}
-
-{% block breadcrumbs %}
- <ul class="breadcrumbs breadcrumbs--with-menu">
- <li>
- <a href="{% url "dashboard:product-list" %}" class="breadcrumbs--ellipsed-item">
- {% trans "Products" context "Dashboard products list" %}
- </a>
- </li>
- <li>
- <a href="{% url "dashboard:product-update" pk=product.pk %}" class="breadcrumbs--ellipsed-item">
- {{ product }}
- </a>
- </li>
- <li>
- <span class="hide-on-med-and-down">
- {% trans "Delete product" context "Product delete breadcrumbs" %}
- </span>
- <span class="hide-on-large-only">
- {% blocktrans trimmed context "Product delete breadcrumbs" %}
- Delete {{ product }}
- {% endblocktrans %}
- </span>
- </li>
- </ul>
-{% endblock %}
-
-{% block menu_catalogue_class %} active{% endblock %}
-
-{% block content %}
- <form method="post" novalidate>
- {% csrf_token %}
- <div class="row">
- <div class="col m6 l4">
- <div class="card">
- <div class="card-content">
- <img src="{% product_first_image product size="255x255" method="crop" %}"
- srcset="{% product_first_image product size="255x255" method="crop" %} 1x, {% product_first_image product size="510x510" method="crop" %} 2x"
- alt="" class="responsive-img">
- </div>
- <div class="card-action">
- <button type="submit" class="card-link">
- {% trans "Delete" context "Dashboard delete action" %}
- </button>
- </div>
- </div>
- </div>
- </div>
- </form>
-{% endblock %}
diff --git a/templates/dashboard/product/product_image_confirm_delete.html b/templates/dashboard/product/product_image_confirm_delete.html
deleted file mode 100644
index 2100d6b7d2..0000000000
--- a/templates/dashboard/product/product_image_confirm_delete.html
+++ /dev/null
@@ -1,66 +0,0 @@
-{% extends "dashboard/base.html" %}
-{% load i18n %}
-{% load product_first_image from product_images %}
-
-{% block title %}
- {% trans "Delete image" context "Delete image page title" %} - {{ block.super }}
-{% endblock %}
-
-{% block body_class %}body-store body-products{% endblock %}
-
-{% block header_menu %}
- {% url "dashboard:product-update" pk=product.pk as url %}
- {% include "dashboard/includes/_back-link.html" with url=url hash="#images" %}
-{% endblock %}
-
-{% block breadcrumbs %}
- <ul class="breadcrumbs breadcrumbs--with-menu">
- <li>
- <a href="{% url "dashboard:product-list" %}" class="breadcrumbs--ellipsed-item">
- {% trans "Products" context "Dashboard products list" %}
- </a>
- </li>
- <li>
- <a href="{% url "dashboard:product-update" pk=product.pk %}" class="breadcrumbs--ellipsed-item">
- {{ product }}
- </a>
- </li>
- <li>
- {% trans "Delete image" context "Delete image breadcrumbs" %}
- </li>
- </ul>
-{% endblock %}
-
-{% block content %}
- <form method="post" novalidate>
- {% csrf_token %}
- <input type="hidden" name="success_url" value="{% url 'dashboard:product-update' pk=product.pk %}#images">
- <div class="row">
- <p>
- {% trans "Are you sure you want to delete the following image?" context "Delete image text" %}
- </p>
- <div class="col m6 l4 offset-m3 offset-l4">
- <div class="card">
- <div class="card-content">
- <div class="card-title black-text">
- {{ product_image.alt }}
- </div>
- <img src="{% product_first_image product size="255x255" method="crop" %}"
- srcset="{% product_first_image product size="255x255" method="crop" %} 1x, {% product_first_image product size="510x510" method="crop" %} 2x"
- alt="{{ product_image.alt }}" class="responsive-img">
- </div>
- </div>
- </div>
- </div>
- <div class="row">
- <div class="col m6 l4 offset-m3 offset-l4 right-align">
- <a href="{% url 'dashboard:product-update' pk=product.pk %}#images" class="btn-flat">
- {% trans "Cancel" context "Dashboard cancel action" %}
- </a>
- <button type="submit" class="btn materialize-red">
- {% trans "Delete" context "Dashboard delete action" %}
- </button>
- </div>
- </div>
- </form>
-{% endblock %}
diff --git a/templates/dashboard/product/product_image_form.html b/templates/dashboard/product/product_image_form.html
index dd8fca414c..35a50dc321 100644
--- a/templates/dashboard/product/product_image_form.html
+++ b/templates/dashboard/product/product_image_form.html
@@ -16,19 +16,19 @@
{% block menu_products_class %}active{% endblock %}
{% block header_menu %}
- {% url "dashboard:product-update" pk=product.pk as url %}
- {% include "dashboard/includes/_back-link.html" with url=url hash="#images" %}
+ {% url "dashboard:product-detail" pk=product.pk as url %}
+ {% include "dashboard/includes/_back-link.html" with url=url %}
{% endblock %}
{% block breadcrumbs %}
<ul class="breadcrumbs breadcrumbs--history">
<li>
- <a href="{% url "dashboard:product-update" pk=product.pk %}#images" class="breadcrumbs--ellipsed-item">
+ <a href="{% url "dashboard:product-detail" pk=product.pk %}" class="breadcrumbs--ellipsed-item">
{{ product }}
</a>
</li>
<li class="back-mobile">
- <a href="{% url "dashboard:product-update" pk=product.pk %}#images" class="breadcrumb">
+ <a href="{% url "dashboard:product-detail" pk=product.pk %}" class="breadcrumb">
<svg data-src="{% static "dashboard/images/arrow_left.svg" %}" fill="#fff" width="20px" height="20px" />
</a>
</li>
diff --git a/templates/dashboard/product/product_variant_confirm_delete.html b/templates/dashboard/product/product_variant_confirm_delete.html
deleted file mode 100644
index 6088d89820..0000000000
--- a/templates/dashboard/product/product_variant_confirm_delete.html
+++ /dev/null
@@ -1,74 +0,0 @@
-{% extends "dashboard/base.html" %}
-{% load i18n %}
-
-{% block title %}
- {% trans "Delete variant" context "Delete variant page title" %} - {{ block.super }}
-{% endblock %}
-
-{% block body_class %}body-store body-products{% endblock %}
-
-{% block header_menu %}
- {% url "dashboard:product-update" pk=product.pk as url %}
- {% include "dashboard/includes/_back-link.html" with url=url hash="#variants" %}
-{% endblock %}
-
-{% block breadcrumbs %}
- <ul class="breadcrumbs breadcrumbs--with-menu">
- <li>
- <a href="{% url "dashboard:product-list" %}" class="breadcrumbs--ellipsed-item">
- {% trans "Products" context "Dashboard products list" %}
- </a>
- </li>
- <li>
- <a href="{% url "dashboard:product-update" pk=product.pk %}#variants" class="breadcrumbs--ellipsed-item">
- {{ product }}
- </a>
- </li>
- <li>
- <span class="hide-on-med-and-down">
- {% trans "Delete variant" context "Delete variant breadcrumbs" %}
- </span>
- <span class="hide-on-large-only">
- {% blocktrans trimmed context "Delete variant breadcrumbs" %}
- Delete variant for {{ product }}
- {% endblocktrans %}
- </span>
- </li>
- </ul>
-{% endblock %}
-
-{% block menu_catalogue_class %} active{% endblock %}
-
-{% block content %}
- <form method="post">
- {% csrf_token %}
- <input type="hidden" name="success_url" value="{% url 'dashboard:product-update' pk=product.pk %}#variants">
- <div class="row">
- <div class="col m6 l4">
- <div class="card">
- <div class="card-content">
- {% if is_only_variant %}
- <p>
- {% blocktrans trimmed context "Delete variant text" %}
- This is the only variant.
- Deleting it will make the product unavailable for your customers.
- {% endblocktrans %}
- </p>
- {% endif %}
- <h5>
- {{ variant }}
- {% if variant.name %}
- {{ variant.name }}
- {% endif %}
- </h5>
- </div>
- <div class="card-action">
- <button type="submit" class="card-link btn btn-flat">
- {% trans "Delete" context "Dashboard delete action" %}
- </button>
- </div>
- </div>
- </div>
- </div>
- </form>
-{% endblock %}
diff --git a/templates/dashboard/product/stock_confirm_delete.html b/templates/dashboard/product/stock_confirm_delete.html
deleted file mode 100644
index 5c6d5fa21a..0000000000
--- a/templates/dashboard/product/stock_confirm_delete.html
+++ /dev/null
@@ -1,63 +0,0 @@
-{% extends "dashboard/base.html" %}
-{% load i18n %}
-
-{% block title %}
- {% trans "Delete stock" context "Delete stock page title" %} - {{ block.super }}
-{% endblock %}
-
-{% block body_class %}body-store body-products{% endblock %}
-
-{% block header_menu %}
- {% url "dashboard:product-update" pk=product.pk as url %}
- {% include "dashboard/includes/_back-link.html" with url=url hash="#stock" %}
-{% endblock %}
-
-{% block breadcrumbs %}
- <ul class="breadcrumbs breadcrumbs--with-menu">
- <li>
- <a href="{% url "dashboard:product-list" %}" class="breadcrumbs--ellipsed-item">
- {% trans "Products" context "Dashboard products list" %}
- </a>
- </li>
- <li>
- <a href="{% url "dashboard:product-update" pk=product.pk %}#stock" class="breadcrumbs--ellipsed-item">
- {{ product }}
- </a>
- </li>
- <li>
- <span class="hide-on-med-and-down">
- {% trans "Delete stock" context "Delete stock breadcrumbs" %}
- </span>
- <span class="hide-on-large-only">
- {% blocktrans trimmed context "Delete stock breadcrumbs" %}
- Delete stock for {{ product }}
- {% endblocktrans %}
- </span>
- </li>
- </ul>
-{% endblock %}
-
-{% block menu_catalogue_class %} active{% endblock %}
-
-{% block content %}
- <form method="post">
- {% csrf_token %}
- <input type="hidden" name="success_url" value="{% url 'dashboard:product-update' pk=product.pk %}#stock">
- <div class="row">
- <div class="col m6 l4">
- <div class="card">
- <div class="card-content">
- <h5>
- {{ stock.variant.sku }} ({{ stock.variant.name }}) &ndash; {{ stock.location }}
- </h5>
- </div>
- <div class="card-action">
- <button type="submit" class="card-link btn btn-flat">
- {% trans "Delete" context "Dashboard delete action" %}
- </button>
- </div>
- </div>
- </div>
- </div>
- </form>
-{% endblock %}
diff --git a/templates/dashboard/product/stock_form.html b/templates/dashboard/product/stock_form.html
index 3cb7846771..115413ac50 100644
--- a/templates/dashboard/product/stock_form.html
+++ b/templates/dashboard/product/stock_form.html
@@ -31,12 +31,12 @@
</a>
</li>
<li class="back-mobile">
- <a href="{% url "dashboard:product-update" pk=product.pk %}#stock">
+ <a href="{% url "dashboard:product-detail" pk=product.pk %}">
<svg data-src="{% static "dashboard/images/chevron_left.svg" %}" />
</a>
</li>
<li>
- <a href="{% url "dashboard:product-update" pk=product.pk %}#stock" class="breadcrumbs--ellipsed-item">
+ <a href="{% url "dashboard:product-detail" pk=product.pk %}" class="breadcrumbs--ellipsed-item">
{{ product }}
</a>
</li>
@@ -77,7 +77,6 @@
<form method="post" id="form-stock" enctype="multipart/form-data">
<div class="card-content">
{% csrf_token %}
- <input type="hidden" name="success_url" value="{% url 'dashboard:product-update' pk=product.pk %}#stock">
<div class="row">
<div class="col s12 m8">
<div class="row">
diff --git a/templates/dashboard/product/variant_form.html b/templates/dashboard/product/variant_form.html
index acac150959..6a85493e26 100644
--- a/templates/dashboard/product/variant_form.html
+++ b/templates/dashboard/product/variant_form.html
@@ -27,12 +27,12 @@
</a>
</li>
<li class="back-mobile">
- <a href="{% url "dashboard:product-update" pk=product.pk %}">
+ <a href="{% url "dashboard:product-detail" pk=product.pk %}">
<svg data-src="{% static "dashboard/images/chevron_left.svg" %}" />
</a>
</li>
<li>
- <a href="{% url "dashboard:product-update" pk=product.pk %}" class="breadcrumbs--ellipsed-item">
+ <a href="{% url "dashboard:product-detail" pk=product.pk %}" class="breadcrumbs--ellipsed-item">
{{ product }}
</a>
</li>
diff --git a/templates/product/details.html b/templates/product/details.html
index bf28769387..888006a0d6 100644
--- a/templates/product/details.html
+++ b/templates/product/details.html
@@ -83,7 +83,7 @@
{{ product }}
</h1>
{% if user.is_staff %}
- <p><a href="{% url "dashboard:product-update" pk=product.pk %}">
+ <p><a href="{% url "dashboard:product-detail" pk=product.pk %}">
{% trans "Edit in dashboard" context "Product details link text" %}
</a></p>
{% endif %}