Skip to content

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

Display images

Mira Szewczyk0c7c688d0052
diff --git a/saleor/dashboard/product/urls.py b/saleor/dashboard/product/urls.py
index 3192761eba..c1d6dac510 100644
--- a/saleor/dashboard/product/urls.py
+++ b/saleor/dashboard/product/urls.py
@@ -45,6 +45,8 @@ urlpatterns = [
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]+)/images/$', views.product_images,
+ name='product-image-list'),
url(r'^(?P<product_pk>[0-9]+)/images/(?P<img_pk>[0-9]+)/$',
views.product_image_edit, name='product-image-update'),
url(r'^(?P<product_pk>[0-9]+)/images/add/$',
diff --git a/saleor/dashboard/product/views.py b/saleor/dashboard/product/views.py
index 2ead4a1149..5b7efeb564 100644
--- a/saleor/dashboard/product/views.py
+++ b/saleor/dashboard/product/views.py
@@ -13,8 +13,7 @@ from ...core.utils import get_paginator_items
from ...product.models import (Product, ProductAttribute, ProductClass,
ProductImage, ProductVariant, Stock,
StockLocation)
-from ...product.utils import (get_product_attributes_data, get_availability,
- price_range_as_dict)
+from ...product.utils import (get_availability)
from ..views import staff_member_required
@@ -135,14 +134,17 @@ def product_create(request, class_pk):
@staff_member_required
def product_detail(request, pk):
- products = Product.objects.prefetch_related('variants').all()
+ products = Product.objects.prefetch_related(
+ 'variants', 'images',
+ 'product_class__variant_attributes__values').all()
product = get_object_or_404(products, pk=pk)
variants = product.variants.all()
+ images = product.images.all()
availability = get_availability(product)
sale_price = availability.price_range
gross_price_range = product.get_gross_price_range()
- ctx = {'product': product, 'sale_price': sale_price,
- 'gross_price_range': gross_price_range, 'variants': variants}
+ ctx = {'product': product, 'sale_price': sale_price, 'variants': variants,
+ 'gross_price_range': gross_price_range, 'images': images}
return TemplateResponse(
request, 'dashboard/product/product_detail.html', ctx)
@@ -254,6 +256,15 @@ def stock_bulk_delete(request, product_pk):
return redirect('dashboard:product-update', pk=product.pk)
+@staff_member_required
+def product_images(request, product_pk):
+ product = get_object_or_404(
+ Product.objects.prefetch_related('images'), pk=product_pk)
+ images = product.images.all()
+ ctx = {'product': product, 'images': images}
+ return TemplateResponse(request, 'dashboard/product/images.html', ctx)
+
+
@staff_member_required
def product_image_edit(request, product_pk, img_pk=None):
product = get_object_or_404(Product, pk=product_pk)
diff --git a/templates/dashboard/product/images.html b/templates/dashboard/product/images.html
new file mode 100644
index 0000000000..d5842be665
--- /dev/null
+++ b/templates/dashboard/product/images.html
@@ -0,0 +1,134 @@
+{% extends "dashboard/base.html" %}
+
+{% load i18n %}
+{% load staticfiles %}
+
+{% block title %}
+ {{ product }} - {% trans "Images" %}
+{% endblock %}
+
+{% block body_class %}body-products{% endblock %}
+
+{% block menu_products_class %}active{% endblock %}
+
+{% block breadcrumbs %}
+ <ul class="breadcrumbs breadcrumbs--history">
+ <li>
+ <a href="{% url "dashboard:product-list" %}" class="breadcrumb">
+ {% trans "Products" context "Dashboard products list" %}
+ </a>
+ </li>
+ <li class="back-mobile">
+ <a href="{% url "dashboard:product-list" %}">
+ <svg data-src="{% static "dashboard/images/arrow_left.svg" %}" fill="#fff" width="20px" height="20px" />
+ </a>
+ </li>
+ <li>
+ <a href="{% url "dashboard:product-detail" product.pk %}">{{ product }}</a>
+ </li>
+ <li>
+ <span class="breadcrumbs--ellipsed-item">{% trans "Images" %}</span>
+ </li>
+ </ul>
+{% endblock %}
+
+{% block menu_catalogue_class %} active{% endblock %}
+
+{% block content %}
+ <div id="images" class="tab-content">
+ <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 %}">
+ {% for image in images %}
+ <li class="col s6 m3 product-gallery-item" data-id="{{ image.pk }}">
+ <div class="row">
+ <div class="card">
+ <div class="card-image product-gallery-item-image">
+ <img class="responsive-img"
+ src="{{ image.image.crop.255x255 }}"
+ srcset="{{ image.image.crop.255x255 }} 1x, {{ image.image.crop.510x510 }} 2x"
+ alt="">
+ </div>
+ <div class="card-content">
+ <span class="product-gallery-item-title card-title black-text" title="{{ image.alt }}">
+ {% if image.alt %}
+ {{ image.alt }}
+ {% else %}
+ <span class="grey-text">
+ {% trans "No description" context "Image card text" %}
+ </span>
+ {% endif %}
+ </span>
+ </div>
+ <div class="sortable__drag-area"></div>
+ <div class="card-action">
+ <a class="btn btn-flat" href="{% url 'dashboard:product-image-update' product_pk=product.pk img_pk=image.pk %}">
+ {% trans "Edit" context "Dashboard edit action" %}
+ </a>
+ <a href="#base-modal" class="btn btn-flat modal-trigger-custom" data-href="{% url 'dashboard:product-image-delete' product_pk=product.pk img_pk=image.pk %}">
+ {% trans "Delete" context "Dashboard delete action" %}
+ </a>
+ </div>
+ </div>
+ </div>
+ </li>
+ {% endfor %}
+ </ul>
+ {% else %}
+ <p class="no-images">
+ {% trans "This product has no images yet." context "Empty image gallery message" %}
+ </p>
+ {% endif %}
+ <div class="col s6 m3 product-gallery-item dropzone-message">
+ <div class="row">
+ <span class="product-gallery-item-title product-gallery-item-title--noclip card-title black-text">
+ <span class="grey-text hide-on-med-and-down">
+ {% trans "Drop images here to upload" context "Image gallery upload box text" %}
+ </span>
+ </span>
+ </div>
+ </div>
+ </div>
+ </form>
+ <script type="application/template" id="template">
+ <li class="col s6 m3 product-gallery-item dz-preview dz-file-preview" data-id="{{ image.pk }}">
+ <div class="row">
+ <div class="card">
+ <div class="card-image product-gallery-item-image">
+ <img data-dz-thumbnail />
+ </div>
+ <div class="dz-progress">
+ <span class="dz-upload" data-dz-uploadprogress></span>
+ </div>
+ <div class="card-content">
+ <span class="product-gallery-item-title card-title black-text">
+ <span class="grey-text">
+ {% trans "No description" context "Empty image gallery message" %}
+ </span>
+ </span>
+ </div>
+ <div class="sortable__drag-area"></div>
+ <div class="card-action">
+ <a class="card-action-edit" href="{% url 'dashboard:product-image-update' product_pk=product.pk img_pk=0 %}">
+ {% trans "Edit" context "Dashboard edit action" %}
+ </a>
+ <a href="#base-modal" class="card-action-delete modal-trigger-custom"
+ data-href="{% url 'dashboard:product-image-delete' product_pk=product.pk img_pk=0 %}">
+ {% trans "Delete" context "Dashboard delete action" %}
+ </a>
+ </div>
+ </div>
+ </div>
+ </li>
+ </script>
+ </div>
+ <div class="fixed-action-btn">
+ <a class="btn-fab btn-fab-hidden btn-floating btn-large waves-effect waves-light teal" id="images-btn" href="{% url 'dashboard:product-image-add' product_pk=product.pk %}" title="{% trans "Add image" context "Add image button text" %}">
+ <svg data-src="{% static "dashboard/images/add.svg" %}" />
+ </a>
+ </div>
+{% endblock %}
\ No newline at end of file
diff --git a/templates/dashboard/product/product_detail.html b/templates/dashboard/product/product_detail.html
index bf4e1df279..ddbb71eb55 100644
--- a/templates/dashboard/product/product_detail.html
+++ b/templates/dashboard/product/product_detail.html
@@ -94,7 +94,7 @@
</div>
</div>
</div>
- <div class="tab-content" id="details">
+ <div class="tab-content" id="variants">
<div class="row">
<div class="col m12 l12">
<div class="card">
@@ -128,4 +128,26 @@
</div>
</div>
</div>
+ <div class="tab-content" id="images">
+ <div class="row">
+ <div class="col m12 l12">
+ <div class="card">
+ <span class="card-title">{% trans "Images" %}</span>
+ {% for image in images %}
+ <div class="row">
+ <div class="col s4 m2">
+ <div class="card-image product-gallery-item-image">
+ <img class="responsive-img"
+ src="{{ image.image.crop.255x255 }}"
+ srcset="{{ image.image.crop.255x255 }} 1x, {{ image.image.crop.510x510 }} 2x"
+ alt="{{ image.alt }}">
+ </div>
+ </div>
+ </div>
+ {% endfor %}
+ <a href="{% url 'dashboard:product-image-list' product.pk %}" class="btn waves-effect waves-light">{% trans "Edit images" %}</a>
+ </div>
+ </div>
+ </div>
+ </div>
{% endblock %}
diff --git a/templates/dashboard/product/product_form.html b/templates/dashboard/product/product_form.html
index e9d5f7d438..5c87365422 100644
--- a/templates/dashboard/product/product_form.html
+++ b/templates/dashboard/product/product_form.html
@@ -80,14 +80,6 @@
<svg data-src="{% static "dashboard/images/store.svg" %}" width="24" height="24" />
</a>
</li>
- <li class="tab col s3" role="presentation">
- <a href="#images" role="tab">
- <span>
- {% trans "Images" context "Product form tab" %}
- </span>
- <svg data-src="{% static "dashboard/images/collections.svg" %}" width="24" height="24" />
- </a>
- </li>
</ul>
</div>
</div>
@@ -351,97 +343,7 @@
<input type="hidden" name="success_url" value="{% url 'dashboard:product-update' pk=product.pk %}#stock">
</form>
</div>
- <div id="images" class="tab-content">
- <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 %}">
- {% for image in images %}
- <li class="col s6 m3 product-gallery-item" data-id="{{ image.pk }}">
- <div class="row">
- <div class="card">
- <div class="card-image product-gallery-item-image">
- <img class="responsive-img"
- src="{{ image.image.crop.255x255 }}"
- srcset="{{ image.image.crop.255x255 }} 1x, {{ image.image.crop.510x510 }} 2x"
- alt="">
- </div>
- <div class="card-content">
- <span class="product-gallery-item-title card-title black-text" title="{{ image.alt }}">
- {% if image.alt %}
- {{ image.alt }}
- {% else %}
- <span class="grey-text">
- {% trans "No description" context "Image card text" %}
- </span>
- {% endif %}
- </span>
- </div>
- <div class="sortable__drag-area"></div>
- <div class="card-action">
- <a class="btn btn-flat" href="{% url 'dashboard:product-image-update' product_pk=product.pk img_pk=image.pk %}">
- {% trans "Edit" context "Dashboard edit action" %}
- </a>
- <a href="#base-modal" class="btn btn-flat modal-trigger-custom" data-href="{% url 'dashboard:product-image-delete' product_pk=product.pk img_pk=image.pk %}">
- {% trans "Delete" context "Dashboard delete action" %}
- </a>
- </div>
- </div>
- </div>
- </li>
- {% endfor %}
- </ul>
- {% else %}
- <p class="no-images">
- {% trans "This product has no images yet." context "Empty image gallery message" %}
- </p>
- {% endif %}
- <div class="col s6 m3 product-gallery-item dropzone-message">
- <div class="row">
- <span class="product-gallery-item-title product-gallery-item-title--noclip card-title black-text">
- <span class="grey-text hide-on-med-and-down">
- {% trans "Drop images here to upload" context "Image gallery upload box text" %}
- </span>
- </span>
- </div>
- </div>
- </div>
- </form>
- <script type="application/template" id="template">
- <li class="col s6 m3 product-gallery-item dz-preview dz-file-preview" data-id="{{ image.pk }}">
- <div class="row">
- <div class="card">
- <div class="card-image product-gallery-item-image">
- <img data-dz-thumbnail />
- </div>
- <div class="dz-progress">
- <span class="dz-upload" data-dz-uploadprogress></span>
- </div>
- <div class="card-content">
- <span class="product-gallery-item-title card-title black-text">
- <span class="grey-text">
- {% trans "No description" context "Empty image gallery message" %}
- </span>
- </span>
- </div>
- <div class="sortable__drag-area"></div>
- <div class="card-action">
- <a class="card-action-edit" href="{% url 'dashboard:product-image-update' product_pk=product.pk img_pk=0 %}">
- {% trans "Edit" context "Dashboard edit action" %}
- </a>
- <a href="#base-modal" class="card-action-delete modal-trigger-custom"
- data-href="{% url 'dashboard:product-image-delete' product_pk=product.pk img_pk=0 %}">
- {% trans "Delete" context "Dashboard delete action" %}
- </a>
- </div>
- </div>
- </div>
- </li>
- </script>
- </div>
+
<div class="fixed-action-btn">
<a class="btn-fab btn-fab-hidden btn-floating btn-large waves-effect waves-light teal" id="images-btn" href="{% url 'dashboard:product-image-add' product_pk=product.pk %}" title="{% trans "Add image" context "Add image button text" %}">
<svg data-src="{% static "dashboard/images/add.svg" %}" />
diff --git a/templates/dashboard/product/product_image_form.html b/templates/dashboard/product/product_image_form.html
index 4c9f79712b..c70635e8af 100644
--- a/templates/dashboard/product/product_image_form.html
+++ b/templates/dashboard/product/product_image_form.html
@@ -62,7 +62,7 @@
<form method="post" enctype="multipart/form-data">
<div class="card-content">
{% csrf_token %}
- <input type="hidden" name="success_url" value="{% url 'dashboard:product-update' pk=product.pk %}#images">
+ <input type="hidden" name="success_url" value="{% url 'dashboard:product-image-list' product.pk %}">
<div class="row">
<div class="col s12 m8">
<div class="row">
@@ -88,14 +88,14 @@
</div>
<div class="card-action right-align">
{% if product_image.pk %}
- <a href="{% url "dashboard:product-update" pk=product.pk %}#images" class="btn btn-flat">
+ <a href="{% url "dashboard:product-image-list" product.pk %}" class="btn btn-flat">
{% trans "Cancel" context "Dashboard cancel action" %}
</a>
<button type="submit" class="btn waves-effect waves-light">
{% trans "Update" context "Dashboard update action" %}
</button>
{% else %}
- <a href="{% url "dashboard:product-update" pk=product.pk %}#images" class="btn btn-flat">
+ <a href="{% url "dashboard:product-image-list" product.pk %}" class="btn btn-flat">
{% trans "Cancel" context "Dashboard cancel action" %}
</a>
<button type="submit" class="btn waves-effect waves-light">