Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Create detail view for products in dashboard
Mira Szewczyk1285c053d94e
diff --git a/saleor/dashboard/product/urls.py b/saleor/dashboard/product/urls.pyindex bce28162f3..85797a70d1 100644--- a/saleor/dashboard/product/urls.py+++ b/saleor/dashboard/product/urls.py@@ -7,6 +7,7 @@ from . import viewsurlpatterns = [url(r'^$',views.product_list, name='product-list'),+ url(r'^(?P<pk>[0-9]+)/$', views.product_detail, name='product-detail'),url(r'^(?P<pk>[0-9]+)/update/$',views.product_edit, name='product-update'),url(r'^(?P<pk>[0-9]+)/delete/$',diff --git a/saleor/dashboard/product/views.py b/saleor/dashboard/product/views.pyindex f1038cef14..91ccfeb1ca 100644--- a/saleor/dashboard/product/views.py+++ b/saleor/dashboard/product/views.py@@ -13,6 +13,7 @@ from ...core.utils import get_paginator_itemsfrom ...product.models import (Product, ProductAttribute, ProductClass,ProductImage, ProductVariant, Stock,StockLocation)+from ...product.utils import get_product_attributes_datafrom ..views import staff_member_required@@ -123,7 +124,7 @@ def product_create(request, class_pk):msg = pgettext_lazy('Dashboard message', 'Added product %s') % productmessages.success(request, msg)- return redirect('dashboard:product-update',+ return redirect('dashboard:product-detail',pk=product.pk)ctx = {'product_form': product_form, 'variant_form': variant_form,@@ -132,6 +133,17 @@ def product_create(request, class_pk):request, 'dashboard/product/product_form.html', ctx)+@staff_member_required+def product_detail(request, pk):+ products = Product.objects.select_related('product_class').prefetch_related(+ 'product_class__product_attributes__values', 'categories').all()+ product = get_object_or_404(products, pk=pk)+ attributes = get_product_attributes_data(product)+ ctx = {'product': product, 'attributes': attributes}+ return TemplateResponse(+ request, 'dashboard/product/product_detail.html', ctx)++@staff_member_requireddef product_edit(request, pk):product = get_object_or_404(@@ -163,7 +175,7 @@ def product_edit(request, pk):msg = pgettext_lazy('Dashboard message', 'Updated product %s') % productmessages.success(request, msg)- return redirect('dashboard:product-update', pk=product.pk)+ 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,diff --git a/templates/dashboard/product/list.html b/templates/dashboard/product/list.htmlindex 5db902f5aa..2ffb7bc65b 100644--- a/templates/dashboard/product/list.html+++ b/templates/dashboard/product/list.html@@ -46,9 +46,9 @@<ul class="collection list">{% for product in products %}<li class="collection-item avatar list-item">- <a href="{% url 'dashboard:product-update' pk=product.pk %}">- <img src="{% product_first_image product size="60x60" method="crop" %}"- srcset="{% product_first_image product size="60x60" method="crop" %} 1x, {% product_first_image product size="120x120" method="crop" %} 2x"+ <a href="{% url 'dashboard:product-detail' pk=product.pk %}">+ <img src="{% product_first_image product size="60x60" method="crop" %}"+ srcset="{% product_first_image product size="60x60" method="crop" %} 1x, {% product_first_image product size="120x120" method="crop" %} 2x"alt="" class="circle teal"><span class="title list-item-name">{{ product.name }}diff --git a/templates/dashboard/product/product_detail.html b/templates/dashboard/product/product_detail.htmlnew file mode 100644index 0000000000..017687f362--- /dev/null+++ b/templates/dashboard/product/product_detail.html@@ -0,0 +1,145 @@+{% extends "dashboard/base.html" %}++{% load i18n %}+{% load prices_i18n %}++{% block title %}+ {{ product }} - {% trans "Products" context "Product form page title" %} - {{ block.super }}+{% 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 "Product form breadcrumbs" %}+ </a>+ </li>+ <li class="back-mobile">+ <a href="{% url "dashboard:product-list" %}">+ <i class="material-icons">arrow_back</i>+ </a>+ </li>+ <li>+ <span class="breadcrumbs--ellipsed-item">+ {{ product }}+ </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="{{ product.get_absolute_url }}" target="_blank">+ {% trans "View on site" context "Product action" %}+ </a>+ </li>+ <li>+ <a href="{% url "dashboard:product-update" product.pk %}">+ {% trans "Update product" context "Product action" %}+ </a>+ </li>+ <li>+ <a href="#base-modal" data-href="{% url 'dashboard:product-delete' pk=product.pk %}"+ class="modal-trigger-custom">+ {% trans "Remove product" context "Product action" %}+ </a>+ </li>+ </ul>+{% endblock %}++{% block content %}+ <div class="row">+ <div class="col s12">+ <ul class="tabs">+ <li class="tab col s3" role="presentation">+ <a href="#details" class="active" role="tab">+ <span>+ {% trans "Details" context "Product form tab" %}+ </span>+ </a>+ </li>+ {% if product.product_class.has_variants %}+ <li class="tab col s3" role="presentation">+ <a href="#variants" role="tab">+ <span>+ {% trans "Variants" context "Product form tab" %}+ </span>+ </a>+ </li>+ {% endif %}+ <li class="tab col s3" role="presentation">+ <a href="#stock" role="tab">+ <span>+ {% trans "Stock" context "Product form tab" %}+ </span>+ </a>+ </li>+ <li class="tab col s3" role="presentation">+ <a href="#images" role="tab">+ <span>+ {% trans "Images" context "Product form tab" %}+ </span>+ </a>+ </li>+ </ul>+ </div>+ </div>++ <div class="tab-content" id="details">+ <div class="row">+ <div class="col m12 l12">+ <div class="card">+ <div class="card-content">+ <span class="card-title">{{ product.product_class }}</span>+ <div class="row">+ <div class="col s12 l9">+ <h5>{% trans "Name" context "Product field" %}</h5>+ <p>{{ product.name }}</p>+ </div>+ <div class="col s12 l3">+ <h5>{% trans "Price" context "Product field" %}</h5>+ <p>{% gross product.price %}</p>+ </div>+ {% for attribute, value in attributes.items %}+ <div class="col s12 l9">+ <h5>{{ attribute }}</h5>+ <p>{{ value }}</p>+ </div>+ {% endfor %}+ {% if product.description %}+ <div class="col s12 l9">+ <h5>{% trans "Description" context "Product field" %}</h5>+ <p>{{ product.description }}</p>+ </div>+ {% endif %}+ {% if product.categories.all %}+ <div class="col s12 l9">+ <h5>{% trans "Categories" context "Product field" %}</h5>+ <p>+ {% for category in product.categories.all %}+ {{ category }},+ {% endfor %}+ </p>+ </div>+ {% endif %}+ {% if product.available_on %}+ <div class="col s12 l9">+ <h5>{% trans "Available on" context "Product field" %}</h5>+ <p>{{ product.available_on }}</p>+ </div>+ {% endif %}+ </div>+ </div>+ </div>+ </div>+ </div>+ </div>+{% endblock %}diff --git a/templates/dashboard/product/product_form.html b/templates/dashboard/product/product_form.htmlindex 4d2cb667b2..7785a575a6 100644--- a/templates/dashboard/product/product_form.html+++ b/templates/dashboard/product/product_form.html@@ -47,27 +47,6 @@</ul>{% endblock %}-{% block header_extra %}- {% if product.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="{{ product.get_absolute_url }}" target="_blank">- {% trans "View on site" context "Dashboard preview action" %}- </a>- </li>- <li>- <a href="#base-modal" data-href="{% url 'dashboard:product-delete' pk=product.pk %}"- class="modal-trigger-custom">- {% trans "Remove product" context "Product form action" %}- </a>- </li>- </ul>- {% endif %}-{% endblock %}-{% block menu_catalogue_class %} active{% endblock %}{% block content %}@@ -159,7 +138,7 @@</div><div class="card-action right-align">{% if product.pk %}- <a href="{% url 'dashboard:product-list' %}" class="btn btn-flat">+ <a href="{% url 'dashboard:product-detail' product.pk %}" class="btn btn-flat">{% trans "Cancel" context "Dashboard cancel action" %}</a><button type="submit" class="btn waves-effect waves-light">@@ -385,8 +364,8 @@<div class="row"><div class="card"><div class="card-image product-gallery-item-image">- <img class="responsive-img"- src="{{ image.image.crop.255x255 }}"+ <img class="responsive-img"+ src="{{ image.image.crop.255x255 }}"srcset="{{ image.image.crop.255x255 }} 1x, {{ image.image.crop.510x510 }} 2x"alt=""></div>