Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Add placeholder templatetag
dominik-zeglen9a7f6699dd9b
diff --git a/saleor/core/templatetags/placeholder.py b/saleor/core/templatetags/placeholder.pynew file mode 100644index 0000000000..e53e672386--- /dev/null+++ b/saleor/core/templatetags/placeholder.py@@ -0,0 +1,10 @@+from django.conf import settings+from django.template import Library++register = Library()+++def placeholder(size):+ return '{static_url}images/placeholder{size}x{size}.png'.format(+ static_url=settings.STATIC_URL, size=size)diff --git a/saleor/core/urls.py b/saleor/core/urls.pyindex 67b35e839c..312861d8ab 100644--- a/saleor/core/urls.py+++ b/saleor/core/urls.py@@ -11,7 +11,7 @@ urlpatterns = [name='impersonate-start'),url(r'^impersonate/stop/$', views.stop_impersonate,name='impersonate-stop'),- url(r'^404', views.handle_404, name='handle-404')+ url(r'^404', views.handle_404, name='handle-404'),url(r'^offline$', views.offline, name='offline'),url(r'^manifest\.json$', TemplateView.as_view(template_name='manifest.json', content_type='application/json')),diff --git a/templates/base.html b/templates/base.htmlindex 98afe9d259..98366dae38 100644--- a/templates/base.html+++ b/templates/base.html@@ -2,6 +2,7 @@{% load i18n %}{% load staticfiles %}{% load render_bundle from webpack_loader %}+{% load placeholder %}<html lang="{{ LANGUAGE_CODE }}" class="no-js" data-shipping-options-url="{% url 'cart:shipping-options' %}" data-cart-summary-url="{% url 'cart:cart-summary' %}"><head>diff --git a/templates/cart_dropdown.html b/templates/cart_dropdown.htmlindex c1a2cd068b..b92efeb588 100644--- a/templates/cart_dropdown.html+++ b/templates/cart_dropdown.html@@ -2,6 +2,7 @@{% load staticfiles %}{% load gross from prices_i18n %}{% load get_thumbnail from product_images %}+{% load placeholder %}<div class="container">{% if quantity > 0 %}@@ -13,7 +14,8 @@<img class="cart-dropdown__image lazyload"data-src="{% get_thumbnail line.image size="60x60" %}"data-srcset="{% get_thumbnail line.image size="60x60" %} 1x, {% get_thumbnail line.image size="120x120" %} 2x"- alt="">+ alt=""+ src="{% placeholder size=120 %}"><h3>{{ line.product }}<span>x{{ line.quantity }}</span>@@ -53,7 +55,9 @@{% else %}<div class="text-md-center cart-dropdown__empty"><h3>{% trans "There are no products in your shopping cart." context "Empty cart message" %}</h3>- <img src="{% static 'images/empty-cart-bg.png' %}" srcset="{% static 'images/empty-cart-bg.png' %} 1x, {% static 'images/empty-cart-bg2x.png' %} 2x">+ <img data-src="{% static 'images/empty-cart-bg.png' %}"+ data-srcset="{% static 'images/empty-cart-bg.png' %} 1x, {% static 'images/empty-cart-bg2x.png' %} 2x"+ src="{% placeholder size=255 %}"><a href="{% url 'home' %}" class="btn primary">{% trans "Check out our sales" context "Empty cart link" %}</a></div>{% endif %}diff --git a/templates/category/_items.html b/templates/category/_items.htmlindex df7998a742..0847903566 100644--- a/templates/category/_items.html+++ b/templates/category/_items.html@@ -3,6 +3,7 @@{% load price_range from price_ranges %}{% load product_first_image from product_images %}{% load get_thumbnail from product_images %}+{% load placeholder %}{% for product, availability in products %}<div class="col-6 col-lg-3 product-list">@@ -12,7 +13,8 @@<img class="img-responsive lazyload"data-src="{% product_first_image product method="crop" size="255x255" %}"data-srcset="{% product_first_image product method="crop" size="255x255" %} 1x, {% product_first_image product method="crop" size="510x510" %} 2x"- alt="">+ alt=""+ src="{% placeholder size=255 %}"><span class="product-list-item-name" title="{{ product }}">{{ product }}</span></div>diff --git a/templates/category/index.html b/templates/category/index.htmlindex a531be4d41..1d2fc87eb6 100644--- a/templates/category/index.html+++ b/templates/category/index.html@@ -5,6 +5,7 @@{% load staticfiles %}{% load prices_i18n %}{% load build_absolute_uri from urls %}+{% load placeholder %}{% block footer_scripts %}{{ block.super }}diff --git a/templates/checkout/login.html b/templates/checkout/login.htmlindex 3908d03f5f..67658a6135 100644--- a/templates/checkout/login.html+++ b/templates/checkout/login.html@@ -1,6 +1,7 @@{% extends "checkout/details.html" %}{% load staticfiles %}{% load i18n %}+{% load placeholder %}{% block title %}{% trans "Login" context "Checkout login page title" %} — {{ block.super }}{% endblock %}@@ -9,7 +10,9 @@<div class="col-12 col-md-6"><div class="checkout__login__continue"><h3>{% trans "New customer?" context "Checkout login page title" %}</h3>- <img class="checkout-pirate lazyload" data-src="{% static 'images/login-bg.png' %}" data-srcset="{% static 'images/login-bg.png' %} 1x, {% static 'images/login-bg2x.png' %} 2x">+ <img class="checkout-pirate lazyload"+ data-src="{% static 'images/login-bg.png' %}"+ data-srcset="{% static 'images/login-bg.png' %} 1x, {% static 'images/login-bg2x.png' %} 2x"><p><a href="{% url 'checkout:index' %}" class="btn secondary narrow">{% trans "Continue" context "Checkout login page new users action" %}diff --git a/templates/order/_ordered_items_table.html b/templates/order/_ordered_items_table.htmlindex 8327b303fa..16ef03aae1 100644--- a/templates/order/_ordered_items_table.html+++ b/templates/order/_ordered_items_table.html@@ -4,6 +4,7 @@{% load discount_amount_for from prices %}{% load product_first_image from product_images %}{% load discount_as_negative from voucher %}+{% load placeholder %}{% if order.user == user %}@@ -53,8 +54,9 @@<div class="col-md-6 col-9"><a class="link--clean" href="{% if item_line.product %}{{ item_line.product.get_absolute_url }}{% endif %}"><img data-src="{% product_first_image item_line.product size="60x60" method="crop" %}"- data-srcset="{% product_first_image item_line.product size="60x60" method="crop" %} 1x, {% product_first_image item_line.product size="120x120" method="crop" %} 2x"- class="float-left lazyload">+ data-srcset="{% product_first_image item_line.product size="60x60" method="crop" %} 1x, {% product_first_image item_line.product size="120x120" method="crop" %} 2x"+ class="float-left lazyload"+ src="{% placeholder size=60 %}"><span class="order-details__product__description">{{ item_line.product_name }}</span></a></div>diff --git a/templates/order/checkout_success.html b/templates/order/checkout_success.htmlindex 4d455fa629..e1b31a24a2 100644--- a/templates/order/checkout_success.html+++ b/templates/order/checkout_success.html@@ -3,6 +3,7 @@{% load bootstrap_form from bootstrap4 %}{% load staticfiles %}{% load i18n %}+{% load placeholder %}{% block title %}{% trans "Thank you" context "Checkout success page title" %} — {{ block.super }}{% endblock %}diff --git a/templates/order/checkout_success_anonymous.html b/templates/order/checkout_success_anonymous.htmlindex f63a52ac38..5f2929f5cb 100644--- a/templates/order/checkout_success_anonymous.html+++ b/templates/order/checkout_success_anonymous.html@@ -3,6 +3,7 @@{% load bootstrap_form from bootstrap4 %}{% load staticfiles %}{% load i18n %}+{% load placeholder %}{% block title %}{% trans "Thank you" context "Checkout success page title" %} — {{ block.super }}{% endblock %}diff --git a/templates/product/details.html b/templates/product/details.htmlindex 7d9fc37801..c0a4b14851 100644--- a/templates/product/details.html+++ b/templates/product/details.html@@ -8,6 +8,7 @@{% load staticfiles %}{% load get_thumbnail product_first_image from product_images %}{% load build_absolute_uri from urls %}+{% load placeholder %}{% block title %}{{ product }} — {{ block.super }}{% endblock %}@@ -69,7 +70,9 @@<div class="carousel-item{% if forloop.first %} active{% endif %}"><img class="d-block img-fluid lazyload"data-src="{% get_thumbnail image.image method="crop" size="540x540" %}"- data-srcset="{% get_thumbnail image.image method="crop" size="540x540" %} 1x, {% get_thumbnail image.image method="crop" size="1080x1080" %} 2x" alt="">+ data-srcset="{% get_thumbnail image.image method="crop" size="540x540" %} 1x, {% get_thumbnail image.image method="crop" size="1080x1080" %} 2x"+ alt=""+ src="{% placeholder size=540 %}"></div>{% endfor %}</div>@@ -88,15 +91,16 @@<img data-src="{% get_thumbnail image.image method="crop" size="60x60" %}"data-srcset="{% get_thumbnail image.image method="crop" size="60x60" %} 1x, {% get_thumbnail image.image method="crop" size="120x120" %} 2x"alt=""- class="lazyload">+ class="lazyload"+ src="{% placeholder size=60 %}"></li>{% endif %}{% endfor %}</ol></div>{% else %}- <img data-src="{% static 'images/placeholder540x540.png' %}"- data-srcset="{% static 'images/placeholder540x540.png' %} 1x, {% static 'images/placeholder1080x1080.png' %} 2x"+ <img data-src="{% placeholder size=540 %}"+ data-srcset="{% placeholder size=540 %} 1x, {% placeholder size=1080 %} 2x"alt=""class="img-fluid lazyload">{% endif %}diff --git a/templates/serviceworker.js b/templates/serviceworker.jsindex 19ba67fec2..17cde35536 100644--- a/templates/serviceworker.js+++ b/templates/serviceworker.js@@ -9,29 +9,31 @@ self.addEventListener('install', (e) => {return cache.addAll(['/','/offline'- ])- .then(() => {+ ]).then(() => {self.skipWaiting();})- .catch(e => console.log(e));+ .catch(e => console.error(e));})- .catch(e => console.log(e))+ .catch(e => console.error(e)));});// when the browser fetches a urlself.addEventListener('fetch', (event) => {- if (event.request.url.match(/\.(css|js|svg)$/)) {- console.log(`caching ${event.request.url}`);+ if (event.request.url.match(/http:\/\/.*((\.(css|js|svg)$)|(placeholder\d+x\d+\.png$))/)) {+ console.log(event.request.url);caches.open(cacheName).then(cache => cache.add(event.request.url)).then(() => self.skipWaiting())- .catch(e => console.log(e));+ .catch(e => {+ console.log(event.request.url);+ console.error(e)+ });}event.respondWith(fetch(event.request).catch(() => {- if (!event.request.url.match(/\.(js|css|eot|otf|png|svg|jpg|ttf|woff|woff2)(\?v=[0-9.]+)?$/)) {+ if (!event.request.url.match(/\.(js|css|eot|otf|png|svg|ttf|woff|woff2)(\?v=[0-9.]+)?$/)) {console.log(event.request.url);return caches.match('/offline').then(res => res);