Skip to content

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

Dashboard views, forms

Pacu2d995f87a54a0
diff --git a/saleor/dashboard/category/forms.py b/saleor/dashboard/category/forms.py
index a26b830540..d3817d5a23 100644
--- a/saleor/dashboard/category/forms.py
+++ b/saleor/dashboard/category/forms.py
@@ -5,6 +5,7 @@ from django.utils.translation import pgettext_lazy
from text_unidecode import unidecode
from ...product.models import Category
+from ..product.widgets import ImagePreviewWidget
class CategoryForm(forms.ModelForm):
diff --git a/saleor/dashboard/category/views.py b/saleor/dashboard/category/views.py
index db043557b3..84244d9855 100644
--- a/saleor/dashboard/category/views.py
+++ b/saleor/dashboard/category/views.py
@@ -36,7 +36,8 @@ def category_create(request, root_pk=None):
if root_pk:
root = get_object_or_404(Category, pk=root_pk)
path = root.get_ancestors(include_self=True) if root else []
- form = CategoryForm(request.POST or None, parent_pk=root_pk)
+ form = CategoryForm(
+ request.POST or None, request.FILES or None, parent_pk=root_pk)
if form.is_valid():
category = form.save()
messages.success(
@@ -58,8 +59,9 @@ def category_edit(request, root_pk=None):
if root_pk:
root = get_object_or_404(Category, pk=root_pk)
path = root.get_ancestors(include_self=True) if root else []
- form = CategoryForm(request.POST or None, instance=category,
- parent_pk=category.parent_id)
+ form = CategoryForm(
+ request.POST or None, request.FILES or None, instance=category,
+ parent_pk=category.parent_id)
status = 200
if form.is_valid():
category = form.save()
diff --git a/saleor/dashboard/collection/forms.py b/saleor/dashboard/collection/forms.py
index 2988f32ddf..5c8f64a1a7 100644
--- a/saleor/dashboard/collection/forms.py
+++ b/saleor/dashboard/collection/forms.py
@@ -6,6 +6,7 @@ from text_unidecode import unidecode
from ...product.models import Collection, Product
from ..forms import AjaxSelect2MultipleChoiceField
+from ..product.widgets import ImagePreviewWidget
class CollectionForm(forms.ModelForm):
@@ -22,7 +23,10 @@ class CollectionForm(forms.ModelForm):
'Name'),
'products': pgettext_lazy(
'Products selection',
- 'Products')}
+ 'Products'),
+ 'background_image': pgettext_lazy(
+ 'Products selection',
+ 'Background Image')}
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
diff --git a/saleor/dashboard/collection/views.py b/saleor/dashboard/collection/views.py
index 400ed59175..f886d82371 100644
--- a/saleor/dashboard/collection/views.py
+++ b/saleor/dashboard/collection/views.py
@@ -33,7 +33,8 @@ def collection_list(request):
@permission_required('product.edit_product')
def collection_create(request):
collection = Collection()
- form = CollectionForm(request.POST or None, instance=collection)
+ form = CollectionForm(
+ request.POST or None, request.FILES or None, instance=collection)
if form.is_valid():
collection = form.save()
msg = pgettext_lazy('Collection message', 'Added collection')
@@ -47,7 +48,8 @@ def collection_create(request):
@permission_required('product.edit_product')
def collection_update(request, pk=None):
collection = get_object_or_404(Collection, pk=pk)
- form = CollectionForm(request.POST or None, instance=collection)
+ form = CollectionForm(
+ request.POST or None, request.FILES or None, instance=collection)
if form.is_valid():
collection = form.save()
msg = pgettext_lazy('Collection message', 'Updated collection')
diff --git a/saleor/product/models.py b/saleor/product/models.py
index ac639ed348..e0f29c23ef 100644
--- a/saleor/product/models.py
+++ b/saleor/product/models.py
@@ -29,6 +29,8 @@ class Category(MPTTModel):
parent = models.ForeignKey(
'self', null=True, blank=True, related_name='children',
on_delete=models.CASCADE)
+ background_image = VersatileImageField(
+ upload_to='category_backgrounds', blank=True, null=True)
objects = models.Manager()
tree = TreeManager()
@@ -399,6 +401,8 @@ class Collection(models.Model):
slug = models.SlugField(max_length=128)
products = models.ManyToManyField(
Product, blank=True, related_name='collections')
+ background_image = VersatileImageField(
+ upload_to='collection_backgrounds', blank=True, null=True)
class Meta:
ordering = ['pk']
diff --git a/saleor/settings.py b/saleor/settings.py
index b4acba2dfe..503998282c 100644
--- a/saleor/settings.py
+++ b/saleor/settings.py
@@ -310,7 +310,18 @@ VERSATILEIMAGEFIELD_RENDITION_KEY_SETS = {
('product_small', 'crop__60x60'),
('product_small_2x', 'crop__120x120'),
('product_list', 'crop__255x255'),
- ('product_list_2x', 'crop__510x510')]}
+ ('product_list_2x', 'crop__510x510')],
+ 'category': [
+ ('background_image_small', 'crop__425x410'),
+ ('background_image_small_placeholder', 'crop__50x49'),
+ ('background_image_small2x', 'crop__850x820'),
+ ('background_image_medium', 'crop__768x303'),
+ ('background_image_medium_placeholder', 'crop__48x10'),
+ ('background_image_medium2x', 'crop__1536x606'),
+ ('background_image_large', 'crop__1440x303'),
+ ('background_image_large_placeholder', 'crop__50x20'),
+ ('background_image_large2x', 'crop__2880x606'),
+ ]}
VERSATILEIMAGEFIELD_SETTINGS = {
# Images should be pre-generated on Production environment
diff --git a/templates/dashboard/category/form.html b/templates/dashboard/category/form.html
index d548d27564..672c03ef08 100644
--- a/templates/dashboard/category/form.html
+++ b/templates/dashboard/category/form.html
@@ -100,6 +100,9 @@
</div>
</div>
</div>
+ <div class="row">
+ {{ form.background_image|materializecss }}
+ </div>
</div>
<div class="card-action right-align">
{% if path %}
diff --git a/templates/dashboard/collection/detail.html b/templates/dashboard/collection/detail.html
index 710756854b..e745af4746 100644
--- a/templates/dashboard/collection/detail.html
+++ b/templates/dashboard/collection/detail.html
@@ -55,6 +55,9 @@
<div class="row">
{{ form.products|materializecss }}
</div>
+ <div class="row">
+ {{ form.background_image|materializecss }}
+ </div>
</div>
<div class="card-action right-align">
{% if collection.pk %}
diff --git a/templates/product/product_list_base.html b/templates/product/product_list_base.html
index 1c91345ffd..e16305948c 100644
--- a/templates/product/product_list_base.html
+++ b/templates/product/product_list_base.html
@@ -99,6 +99,9 @@
{% endblock %}
{% block content %}
+ <div class="row">
+
+ </div>
<div id="product-list-page">
<div class="row">
<div class="col-md-4 col-lg-3">