Skip to content

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

Fix upload product image dropzone form

Anna Siwikc2f9eb411449
diff --git a/requirements.txt b/requirements.txt
index f8d2a551f0..fb9f0ed7c4 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -31,7 +31,6 @@ django-templated-email==2.2.0
django-versatileimagefield==1.7.1
django-webpack-loader==0.5.0
django==1.11.5
-djangorestframework==3.6.3
dnspython==1.15.0 # via email-validator
docutils==0.14 # via botocore
elasticsearch==5.4.0
@@ -52,6 +51,7 @@ maxminddb-geolite2==2017.803
maxminddb==1.3.0
mock==2.0.0
oauthlib==2.0.4 # via requests-oauthlib, social-auth-core
+olefile==0.44 # via pillow
pbr==3.1.1 # via mock
pillow==4.0.0 # via django-versatileimagefield
prices==0.5.9
diff --git a/saleor/dashboard/product/forms.py b/saleor/dashboard/product/forms.py
index 307c082d5a..d53b49214e 100644
--- a/saleor/dashboard/product/forms.py
+++ b/saleor/dashboard/product/forms.py
@@ -323,10 +323,6 @@ class UploadImageForm(forms.ModelForm):
fields = ('image', )
def __init__(self, *args, **kwargs):
- self.product = kwargs.pop('product')
+ product = kwargs.pop('product')
super(UploadImageForm, self).__init__(*args, **kwargs)
-
- def save(self, commit=True):
- image = super(UploadImageForm, self).save(commit=commit)
- image.product = self.product
- return image.save()
+ self.instance.product = product
diff --git a/saleor/dashboard/product/views.py b/saleor/dashboard/product/views.py
index 2ceef435a0..2390c39f45 100644
--- a/saleor/dashboard/product/views.py
+++ b/saleor/dashboard/product/views.py
@@ -1,6 +1,5 @@
from __future__ import unicode_literals
-import json
from django.contrib import messages
from django.contrib.auth.decorators import permission_required
from django.http import JsonResponse
@@ -582,8 +581,8 @@ def ajax_upload_image(request, product_pk):
status = 200
if form.is_valid():
image = form.save()
- ctx = {'id': image.pk, 'image': image, 'order': image.order}
+ ctx = {'id': image.pk, 'image': None, 'order': image.order}
elif form.errors:
status = 400
- ctx = {'errors': form.errors}
- return JsonResponse(ctx, status=200)
+ ctx = {'error': form.errors}
+ return JsonResponse(ctx, status=status)
diff --git a/templates/dashboard/product/product_image/list.html b/templates/dashboard/product/product_image/list.html
index 63ab7f9686..9b5f048c92 100644
--- a/templates/dashboard/product/product_image/list.html
+++ b/templates/dashboard/product/product_image/list.html
@@ -110,10 +110,10 @@
</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=0 %}">
+ <a class="btn btn-flat 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="btn btn-flat modal-trigger-custom"
+ <a href="#base-modal" class="btn btn-flat 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>
@@ -128,4 +128,4 @@
<svg data-src="{% static "dashboard/images/add.svg" %}" />
</a>
</div>
-{% endblock %}
\ No newline at end of file
+{% endblock %}
diff --git a/tests/dashboard/test_product.py b/tests/dashboard/test_product.py
index 16eb8ffd08..399c0e9898 100644
--- a/tests/dashboard/test_product.py
+++ b/tests/dashboard/test_product.py
@@ -6,7 +6,7 @@ import pytest
from django import forms
from django.core.urlresolvers import reverse
from django.utils.encoding import smart_text
-from mock import Mock, MagicMock
+from mock import Mock
from saleor.dashboard.product.forms import (
ProductClassForm, ProductClassSelectorForm, ProductForm)