Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Fix review remarks
oldPadavan4a63662626d2
diff --git a/saleor/graphql/product/types.py b/saleor/graphql/product/types.pyindex 1b8b289d0c..ccd7247f67 100644--- a/saleor/graphql/product/types.py+++ b/saleor/graphql/product/types.py@@ -130,9 +130,7 @@ class Product(CountableDjangoObjectType):description='The storefront URL for the product.', required=True)thumbnail_url = graphene.String(description='The URL of a main thumbnail for a product.',- size=graphene.Argument(- graphene.Int,- description='Size of thumbnail'))+ size=graphene.Argument(graphene.Int, description='Size of thumbnail'))availability = graphene.Field(ProductAvailability,description="""Informs about product's availability in the storefront,@@ -265,8 +263,7 @@ class ProductImage(CountableDjangoObjectType):url = graphene.String(required=True,description='',- size=graphene.Int(- description='Size of image'))+ size=graphene.Int(description='Size of image'))class Meta:description = 'Represents a product image.'diff --git a/saleor/product/templatetags/product_images.py b/saleor/product/templatetags/product_images.pyindex d0a62121d0..3f4fca9f4e 100644--- a/saleor/product/templatetags/product_images.py+++ b/saleor/product/templatetags/product_images.py@@ -49,9 +49,8 @@ def get_available_sizes_by_method(method):sizes = []for available_size in AVAILABLE_SIZES:available_method, avail_size_str = available_size.split('__')- if available_method != method:- continue- sizes.append(min([int(s) for s in avail_size_str.split('x')]))+ if available_method == method:+ sizes.append(min([int(s) for s in avail_size_str.split('x')]))return sizes@@ -60,8 +59,8 @@ def get_thumbnail_size(size, method):return closest smaller size"""avail_sizes = sorted(get_available_sizes_by_method(method))- larger = list(filter(lambda x: size < x <= size * 2, avail_sizes))- smaller = list(filter(lambda x: x <= size, avail_sizes))+ larger = [x for x in avail_sizes if size < x <= size * 2]+ smaller = [x for x in avail_sizes if x <= size]if larger:return '%sx%s' % (larger[0], larger[0])@@ -76,24 +75,23 @@ def get_thumbnail(instance, size, method='crop'):size_name = '%s__%s' % (method, size_str)on_demand = settings.VERSATILEIMAGEFIELD_SETTINGS['create_images_on_demand']- if not instance:- return static(choose_placeholder(size_str))- used_size = size_str- if size_name not in AVAILABLE_SIZES and not on_demand:- used_size = get_thumbnail_size(size, method)- if not used_size:- msg = (- "Thumbnail size %s is not defined in settings "- "and it won't be generated automatically" % size_name)- warnings.warn(msg)- try:- thumbnail = getattr(instance, method)[used_size]- except Exception:- logger.exception(- 'Thumbnail fetch failed',- extra={'instance': instance, 'size': size})- else:- return thumbnail.url+ if instance:+ used_size = size_str+ if size_name not in AVAILABLE_SIZES and not on_demand:+ used_size = get_thumbnail_size(size, method)+ if not used_size:+ msg = (+ "Thumbnail size %s is not defined in settings "+ "and it won't be generated automatically" % size_name)+ warnings.warn(msg)+ try:+ thumbnail = getattr(instance, method)[used_size]+ except Exception:+ logger.exception(+ 'Thumbnail fetch failed',+ extra={'instance': instance, 'size': size})+ else:+ return thumbnail.urlreturn static(choose_placeholder(size_str))