Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Remove duplicated product_first_image templatetag
Pacu2085393f555a1
diff --git a/saleor/graphql/product/types.py b/saleor/graphql/product/types.pyindex b648fa343f..ab3849ed65 100644--- a/saleor/graphql/product/types.py+++ b/saleor/graphql/product/types.py@@ -3,8 +3,12 @@ from graphene import relayfrom graphene_django.filter import DjangoFilterConnectionFieldfrom ...product import models+<<<<<<< HEADfrom ...product.templatetags.product_images import (get_thumbnail, product_first_image)+=======+from ...product.templatetags.product_images import get_thumbnail+>>>>>>> Remove duplicated product_first_image templatetagfrom ...product.utils import products_with_detailsfrom ...product.utils.availability import get_availabilityfrom ...product.utils.costs import (@@ -154,7 +158,7 @@ class Product(CountableDjangoObjectType):def resolve_thumbnail_url(self, info, *, size=None):if not size:size = 255- return product_first_image(self, size)+ return get_thumbnail(self.get_first_image(), size)def resolve_url(self, info):return self.get_absolute_url()diff --git a/saleor/product/models.py b/saleor/product/models.pyindex ee422daf99..54487258d3 100644--- a/saleor/product/models.py+++ b/saleor/product/models.py@@ -157,8 +157,8 @@ class Product(SeoModel):return self.available_on is None or self.available_on <= todaydef get_first_image(self):- first_image = self.images.first()- return first_image.image if first_image else None+ images = list(self.images.all())+ return images[0].image if images else Nonedef get_price_range(self, discounts=None, taxes=None):if self.variants.exists():diff --git a/saleor/product/templatetags/product_images.py b/saleor/product/templatetags/product_images.pyindex bbd324f854..b192caaccf 100644--- a/saleor/product/templatetags/product_images.py+++ b/saleor/product/templatetags/product_images.py@@ -91,12 +91,4 @@ def get_thumbnail(instance, size, method='crop'):extra={'instance': instance, 'size': size})else:return thumbnail.url- return static(choose_placeholder('%sx%s' % (size, size)))--[email protected]_tag()-def product_first_image(product, size, method='crop'):- """Return the main image of the given product."""- all_images = product.images.all() if product else []- main_image = all_images[0].image if all_images else None- return get_thumbnail(main_image, size, method)+ return static(choose_placeholder(size))diff --git a/templates/dashboard/product/list.html b/templates/dashboard/product/list.htmlindex 3a68890196..759c853cd4 100644--- a/templates/dashboard/product/list.html+++ b/templates/dashboard/product/list.html@@ -2,7 +2,7 @@{% load i18n %}{% load materializecss %}{% load price from taxed_prices %}-{% load product_first_image from product_images %}+{% load get_thumbnail from product_images %}{% load staticfiles %}{% load utils %}@@ -73,8 +73,8 @@<label for="id_products_{{ product.pk }}"></label></td><td class="avatar">- <img src="{% product_first_image product size=60 method="crop" %}"- srcset="{% product_first_image product size=60 method="crop" %} 1x, {% product_first_image product size=120 method="crop" %} 2x"+ <img src="{% get_thumbnail product.get_first_image size=60 method="crop" %}"+ srcset="{% get_thumbnail product.get_first_image size=60 method="crop" %} 1x, {% get_thumbnail product.get_first_image size=120 method="crop" %} 2x"alt=""></td><td>diff --git a/templates/dashboard/search/results.html b/templates/dashboard/search/results.htmlindex 2fcb72a846..7ee31de994 100644--- a/templates/dashboard/search/results.html+++ b/templates/dashboard/search/results.html@@ -2,7 +2,7 @@{% load i18n %}{% load materializecss %}{% load price from taxed_prices %}-{% load product_first_image from product_images %}+{% load get_thumbnail from product_images %}{% load staticfiles %}{% block title %}@@ -27,8 +27,13 @@{% for product in products %}<li class="collection-item avatar list-item"><a href="{% url 'dashboard:product-details' pk=product.pk %}">+<<<<<<< HEAD<img src="{% product_first_image product size=60 method="crop" %}"srcset="{% product_first_image product size=60 method="crop" %} 1x, {% product_first_image product size=120 method="crop" %} 2x"+=======+ <img src="{% get_thumbnail product.get_first_image size="60x60" method="crop" %}"+ srcset="{% get_thumbnail product.get_first_image size="60x60" method="crop" %} 1x, {% get_thumbnail product.get_first_image size="120x120" method="crop" %} 2x"+>>>>>>> Remove duplicated product_first_image templatetagclass="circle" alt="{{ product.name }}"><span class="list-item-name">{{ product.name }}diff --git a/templates/product/_items.html b/templates/product/_items.htmlindex 47f66e1e9a..7bce7f656a 100644--- a/templates/product/_items.html+++ b/templates/product/_items.html@@ -1,7 +1,6 @@{% load i18n %}{% load staticfiles %}{% load taxed_prices %}-{% load product_first_image from product_images %}{% load get_thumbnail from product_images %}{% load placeholder %}@@ -11,8 +10,8 @@<div class="text-center"><div><img class="img-responsive lazyload lazypreload"- data-src="{% product_first_image product method="crop" size=255 %}"- data-srcset="{% product_first_image product method="crop" size=255 %} 1x, {% product_first_image product method="crop" size=510 %} 2x"+ data-src="{% get_thumbnail product.get_first_image method="crop" size=255 %}"+ data-srcset="{% get_thumbnail product.get_first_image method="crop" size=255 %} 1x, {% get_thumbnail product.get_first_image method="crop" size=510 %} 2x"alt=""src="{% placeholder size=255 %}"><span class="product-list-item-name" title="{{ product.translated }}">{{ product.translated }}</span>diff --git a/templates/product/details.html b/templates/product/details.htmlindex af8992ccaf..1b26d5ea36 100644--- a/templates/product/details.html+++ b/templates/product/details.html@@ -3,7 +3,7 @@{% load bootstrap_field from bootstrap4 %}{% load build_absolute_uri from urls %}{% load get_object_properties from attributes %}-{% load get_thumbnail product_first_image from product_images %}+{% load get_thumbnail from product_images %}{% load i18n %}{% load markdown from markdown %}{% load placeholder %}@@ -27,7 +27,7 @@<meta property="og:url" content="{{ product_url }}"><link rel="canonical" href="{{ product_url }}">- {% product_first_image product size=510 as product_image %}+ {% get_thumbnail product.get_first_image size=510 as product_image %}{% if product_image %}<meta property="og:image" content="{{ product_image }}" /><meta property="og:image:width" content="510">diff --git a/tests/test_product_tags.py b/tests/test_product_tags.pyindex 2692988789..cc58da614d 100644--- a/tests/test_product_tags.py+++ b/tests/test_product_tags.py@@ -4,7 +4,7 @@ from django.contrib.staticfiles.templatetags.staticfiles import staticfrom django.test import override_settingsfrom saleor.product.templatetags.product_images import (- choose_placeholder, get_thumbnail, product_first_image)+ choose_placeholder, get_thumbnail, get_thumbnail)@override_settings(@@ -71,20 +71,6 @@ def test_get_thumbnail_no_match_by_method():assert cropped == static('images/placeholder1080x1080.png')-@override_settings(- VERSATILEIMAGEFIELD_SETTINGS={'create_images_on_demand': True})-def test_product_first_image():- mock_product_image = Mock()- mock_product_image.image = Mock()- mock_product_image.image.crop = {'10x10': Mock(url='crop.jpg')}-- mock_queryset = Mock()- mock_queryset.all.return_value = [mock_product_image]- mock_product = Mock(images=mock_queryset)- out = product_first_image(mock_product, 10, method='crop')- assert out == 'crop.jpg'--def test_choose_placeholder(settings):settings.PLACEHOLDER_IMAGES = {10: '10_placeholder',