Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Change appearance of default product image
Adam Bogdał44875553d5de
diff --git a/app.json b/app.jsonindex 891a87b20e..d83bea2527 100644--- a/app.json+++ b/app.json@@ -25,7 +25,7 @@}},"scripts": {- "postdeploy": "saleor makemigrations userprofile && saleor migrate && saleor populatedb"+ "postdeploy": "saleor saleor migrate && saleor populatedb"},"addons": ["heroku-postgresql:hobby-dev"diff --git a/saleor/product/management/commands/populatedb.py b/saleor/product/management/commands/populatedb.pyindex 5c2dfedd3d..3802e16b33 100644--- a/saleor/product/management/commands/populatedb.py+++ b/saleor/product/management/commands/populatedb.py@@ -1,17 +1,16 @@-from os.path import exists, join+from os.path import existsfrom django.core.management.base import BaseCommand, CommandError-from django.core.management import call_commandfrom utils.create_random_data import create_items, create_usersclass Command(BaseCommand):help = 'Populate database with test objects'- BASE_DIR = r'saleor/static/placeholders/'+ placeholders_dir = r'saleor/static/placeholders/'def handle(self, *args, **options):- for msg in create_items(self.BASE_DIR, 10):+ for msg in create_items(self.placeholders_dir, 10):self.stdout.write(msg)for msg in create_users(10):self.stdout.write(msg)diff --git a/saleor/product/templates/category/index.html b/saleor/product/templates/category/index.htmlindex 2e433b974f..1e61db3611 100644--- a/saleor/product/templates/category/index.html+++ b/saleor/product/templates/category/index.html@@ -21,7 +21,7 @@{% if product.images.first %}<img class="img-responsive" src="{{ product.images.first.image.thumbnail.750x750 }}" alt="">{% else %}- <img class="img-responsive" src="http://placehold.it/750x500/&text=Product Image" alt="">+ <img class="img-responsive" src="http://placehold.it/750x750/F5F5F5/AAAAAA?text=Product Image" alt="">{% endif %}</a><h3><a href="{{ product.get_absolute_url }}">{{ product }}</a></h3>diff --git a/saleor/product/templates/product/details.html b/saleor/product/templates/product/details.htmlindex c81ffca831..4b33f23693 100644--- a/saleor/product/templates/product/details.html+++ b/saleor/product/templates/product/details.html@@ -47,7 +47,7 @@{% if product.images.first %}<img class="img-responsive" src="{{ product.images.first.image.thumbnail.750x750 }}" alt="">{% else %}- <img class="img-responsive" src="http://placehold.it/750x750/&text=Product Image" alt="">+ <img class="img-responsive" src="http://placehold.it/750x750/F5F5F5/AAAAAA?text=Product Image" alt="">{% endif %}<hr>@@ -97,7 +97,7 @@</div>{% empty %}<div class="item active">- <img class="img-responsive" src="http://placehold.it/750x750/&text=Product Image" alt="">+ <img class="img-responsive" src="http://placehold.it/750x750/F5F5F5/AAAAAA?text=Product Image" alt=""></div>{% endfor %}</div>diff --git a/utils/create_random_data.py b/utils/create_random_data.pyindex dba7f7c6fe..6fbd52ec92 100644--- a/utils/create_random_data.py+++ b/utils/create_random_data.py@@ -1,31 +1,17 @@from __future__ import unicode_literals-import randomimport os+import randomimport unicodedatafrom faker import Factoryfrom django.core.files import File-from saleor.product.models import (Shirt, ShirtVariant,- Bag, BagVariant, ProductImage)-from saleor.product.models import Category, Color+from saleor.product.models import (Product, ProductVariant, ProductImage, Stock)+from saleor.product.models import Categoryfrom saleor.userprofile.models import User, Address-fake = Factory.create()-PRODUCT_COLLECTIONS = fake.words(10)---def create_color(**kwargs):- r = lambda: random.randint(0, 255)-- defaults = {- 'name': fake.word(),- 'color': '%02X%02X%02X' % (r(), r(), r())- }- defaults.update(kwargs)-- return Color.objects.create(**defaults)+STOCK_LOCATION = 'default'def get_or_create_category(name, **kwargs):@@ -38,43 +24,40 @@ def get_or_create_category(name, **kwargs):return Category.objects.get_or_create(name=name, defaults=defaults)[0]-def create_product(product_type, **kwargs):- if random.choice([True, False]):- collection = random.choice(PRODUCT_COLLECTIONS)- else:- collection = ''-+def create_product(**kwargs):defaults = {'name': fake.company(),'price': fake.pyfloat(2, 2, positive=True),- 'category': Category.objects.order_by('?')[0],- 'collection': collection,- 'color': Color.objects.order_by('?')[0],'weight': fake.random_digit(),'description': '\n\n'.join(fake.paragraphs(5))}defaults.update(kwargs)-- return product_type.objects.create(**defaults)+ return Product.objects.create(**defaults)def create_variant(product, **kwargs):defaults = {- 'stock': fake.random_int(),+ 'name': fake.word(),'sku': fake.random_int(1, 100000),- 'product': product+ 'product': product,}- if isinstance(product, Shirt):- if not 'size' in kwargs:- defaults['size'] = random.choice(ShirtVariant.SIZE_CHOICES)[0]- variant_class = ShirtVariant- elif isinstance(product, Bag):- variant_class = BagVariant- else:- raise NotImplementeddefaults.update(kwargs)+ return ProductVariant.objects.create(**defaults)+- return variant_class.objects.create(**defaults)+def create_stock(product, **kwargs):+ for variant in product.variants.all():+ _create_stock(variant, **kwargs)+++def _create_stock(variant, **kwargs):+ defaults = {+ 'variant': variant,+ 'location': STOCK_LOCATION,+ 'quantity': fake.random_int(1, 50)+ }+ defaults.update(kwargs)+ return Stock.objects.create(**defaults)def create_product_image(product, placeholder_dir):@@ -93,47 +76,26 @@ def create_product_images(product, how_many, placeholder_dir):create_product_image(product, placeholder_dir)-def create_shirt(**kwargs):- return create_product(Shirt, **kwargs)---def create_bag(**kwargs):- return create_product(Bag, **kwargs)--def create_items(placeholder_dir, how_many=10):- # Create few colors- [create_color() for i in range(5)]-- shirt_category = get_or_create_category('Shirts')- bag_category = get_or_create_category('Grocery bags')+ default_category = get_or_create_category('Default')create_images = os.path.exists(placeholder_dir)for i in range(how_many):- # Shirt- shirt = create_shirt(category=shirt_category)- if create_images:- create_product_images(shirt, random.randrange(1, 5),- placeholder_dir + "shirts")- # Bag- bag = create_bag(category=bag_category, collection='')+ product = create_product()+ product.categories.add(default_category)++ create_variant(product) # ensure at least one variantif create_images:- create_product_images(bag, random.randrange(1, 5),- placeholder_dir + "bags")- # chance to generate couple of sizes- for size in ShirtVariant.SIZE_CHOICES:- # Create min. one size- if shirt.variants.count() == 0:- create_variant(shirt, size=size[0])- continue- if random.choice([True, False]):- create_variant(shirt, size=size[0])+ create_product_images(+ product, random.randrange(1, 5), placeholder_dir)- create_variant(bag)+ for _ in range(random.randrange(1, 5)):+ if random.choice([True, False]):+ create_variant(product)- yield "Shirt - %s %s Variants" % (shirt, shirt.variants.count())- yield "Bag - %s %s Variants" % (bag, bag.variants.count())+ create_stock(product)+ yield "Product - %s %s Variants" % (product, product.variants.count())def create_fake_user():