Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Move images list to product details view; remove unused image formset
Marcin Gębala8c86b3815da7
diff --git a/saleor/dashboard/product/forms.py b/saleor/dashboard/product/forms.pyindex a6fbbd071a..b916ea2a2d 100644--- a/saleor/dashboard/product/forms.py+++ b/saleor/dashboard/product/forms.py@@ -45,9 +45,7 @@ formset_defaults = {'validate_min': True}-ProductImageFormSet = inlineformset_factory(- Product, ProductImage, widgets={'image': ImageInputWidget},- exclude=[], **formset_defaults)+ShirtVariantFormset = inlineformset_factory(Shirt, ShirtVariant, exclude=[], **formset_defaults)BagVariantFormset = inlineformset_factory(diff --git a/saleor/dashboard/product/urls.py b/saleor/dashboard/product/urls.pyindex 7a7b8ac135..c0f54de802 100644--- a/saleor/dashboard/product/urls.py+++ b/saleor/dashboard/product/urls.py@@ -14,9 +14,7 @@ urlpatterns = patterns(url(r'^(?P<pk>[0-9]+)/delete/$',views.ProductDeleteView.as_view(), name='product-delete'),- url(r'^(?P<product_pk>[0-9]+)/images/$',- views.product_images_list, name='product-images'),- url(r'^(?P<product_pk>[0-9]+)/images/(?P<img_pk>[0-9]+)/update/$',+ 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/$',views.product_image_edit, name='product-image-add'),diff --git a/saleor/dashboard/product/views.py b/saleor/dashboard/product/views.pyindex 258845a503..9bc2c265ff 100644--- a/saleor/dashboard/product/views.py+++ b/saleor/dashboard/product/views.py@@ -11,7 +11,7 @@ from django.views.generic import DeleteViewfrom ...product.models import Product, ProductImagefrom ..utils import paginatefrom ..views import StaffMemberOnlyMixin, staff_member_required-from .forms import (ProductImageFormSet, ProductClassForm, get_product_form,+from .forms import (ProductClassForm, get_product_form,get_product_cls_by_name, get_variant_formset, ProductImageForm)@@ -35,20 +35,17 @@ def product_details(request, pk=None, cls_name=None):else:product = get_product_cls_by_name(cls_name)()title = _('Add new %s') % cls_name+ images = product.images.all()form_cls = get_product_form(product)variant_formset_cls = get_variant_formset(product)form = form_cls(request.POST or None, instance=product)variant_formset = variant_formset_cls(request.POST or None, instance=product)- image_formset = ProductImageFormSet(- request.POST or None, request.FILES or None, instance=product)- forms = {'form': form, 'variant_formset': variant_formset,- 'image_formset': image_formset}+ forms = {'form': form, 'variant_formset': variant_formset}if all([f.is_valid() for f in forms.values()]):with transaction.atomic():product = form.save()variant_formset.save()- image_formset.save()if pk:msg = _('Updated product %s') % productelse:@@ -59,7 +56,7 @@ def product_details(request, pk=None, cls_name=None):if any([f.errors for f in forms.values()]):messages.error(request, _('Your submitted data was not valid - ''please correct the errors below'))- ctx = {'title': title, 'product': product}+ ctx = {'title': title, 'product': product, 'images': images}ctx.update(forms)return TemplateResponse(request, 'dashboard/product/product_form.html', ctx)@@ -75,14 +72,6 @@ class ProductDeleteView(StaffMemberOnlyMixin, DeleteView):return result-@staff_member_required-def product_images_list(request, product_pk):- product = get_object_or_404(Product, pk=product_pk)- images = product.images.all()- ctx = {'product': product, 'images': images}- return TemplateResponse(request, 'dashboard/product/product_images_list.html', ctx)--@staff_member_requireddef product_image_edit(request, product_pk, img_pk=None):product = get_object_or_404(Product, pk=product_pk)@@ -101,7 +90,7 @@ def product_image_edit(request, product_pk, img_pk=None):else:msg = _('Added image %s') % product_image.image.namemessages.success(request, msg)- return redirect('dashboard:product-images', product_pk=product.pk)+ return redirect('dashboard:product-update', pk=product.pk)else:if form.errors:messages.error(request, _('Your submitted data was not valid - '@@ -117,6 +106,6 @@ def product_image_delete(request, product_pk, img_pk):if request.method == 'POST':product_image.delete()messages.success(request, _('Deleted image %s') % product_image.image.name)- return redirect('dashboard:product-images', product_pk=product.pk)+ return redirect('dashboard:product-update', pk=product.pk)ctx = {'product': product, 'product_image': product_image}return TemplateResponse(request, 'dashboard/product/product_image_confirm_delete.html', ctx)diff --git a/saleor/dashboard/templates/dashboard/product/product_form.html b/saleor/dashboard/templates/dashboard/product/product_form.htmlindex aa0b1d7571..80d53d218d 100644--- a/saleor/dashboard/templates/dashboard/product/product_form.html+++ b/saleor/dashboard/templates/dashboard/product/product_form.html@@ -101,45 +101,6 @@</tbody></table></div>-- {{ image_formset.management_form }}- <div class="panel panel-default">- <div class="panel-heading">- <span class="panel-title">{% trans "Images" %}</span>- </div>- <table class="table">- <thead>- <tr>- <th colspan="1" class="col-sm-11">{% trans "Image" %}</th>- <th class="text-right"><i class="glyphicon glyphicon-trash"></i></th>- </tr>- </thead>- <tbody>- {% for form in image_formset.initial_forms %}- <tr>- <td>- {% for field in form.hidden_fields %}- {{ field }}- {% endfor %}- {{ form.image }}- </td>- <td class="text-right">- {{ form.DELETE }}- </td>- </tr>- {% endfor %}- {% for form in image_formset.extra_forms %}- <tr>- <td>- {{ form.image }}- </td>- <td></td>- </tr>- {% endfor %}- </tbody>- </table>-- </div></div><div class="col-lg-4">diff --git a/saleor/dashboard/templates/dashboard/product/product_image_form.html b/saleor/dashboard/templates/dashboard/product/product_image_form.htmlindex c9b3ba88bc..2d858b7a22 100644--- a/saleor/dashboard/templates/dashboard/product/product_image_form.html+++ b/saleor/dashboard/templates/dashboard/product/product_image_form.html@@ -26,7 +26,7 @@{% else %}<button type="submit" class="btn waves-effect"><i class="glyphicon glyphicon-upload"></i> {% trans "Add" %}</button>{% endif %}- <a href="{% url 'dashboard:product-images' product_pk=product.pk %}" class="btn waves-effect"><i class="glyphicon glyphicon-remove"></i> {% trans "Cancel" %}</a>+ <a href="{% url 'dashboard:product-update' pk=product.pk %}" class="btn waves-effect"><i class="glyphicon glyphicon-remove"></i> {% trans "Cancel" %}</a></div></div></form>diff --git a/saleor/dashboard/templates/dashboard/product/product_images_list.html b/saleor/dashboard/templates/dashboard/product/product_images_list.htmldeleted file mode 100644index 7cdde4b3da..0000000000--- a/saleor/dashboard/templates/dashboard/product/product_images_list.html+++ /dev/null@@ -1,24 +0,0 @@-{% extends "dashboard/base.html" %}-{% load i18n %}-{% load bootstrap %}-{% load static %}--{% block title %}{% trans "Images" %} - {{ block.super }}{% endblock %}--{% block page_title %}{% trans "Images" %}{% endblock %}--{% block content %}- <a class="btn waves-effect" href="{% url 'dashboard:product-image-add' product_pk=product.pk %}">{% trans 'Add image' %}</a>- <ul class="collection">- {% for product_image in images %}- <li class="collection-item">- <img src="{{ product_image.image.crop.50x50 }}" alt="{{ product_image.alt }}">- <span>{{ product_image.image.name }}</span>- <div class="right">- <a href="{% url 'dashboard:product-image-update' product_pk=product.pk img_pk=product_image.pk %}">{% trans 'Edit' %}</a>- <a href="{% url 'dashboard:product-image-delete' product_pk=product.pk img_pk=product_image.pk %}">{% trans 'Delete' %}</a>- </div>- </li>- {% endfor %}- </ul>-{% endblock %}\ No newline at end of file