Skip to content

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

move logic to templatetags

Pacu2e4cb50485ddd
diff --git a/saleor/core/templatetags/attributes.py b/saleor/core/templatetags/attributes.py
index 88c825a597..5f922c2592 100644
--- a/saleor/core/templatetags/attributes.py
+++ b/saleor/core/templatetags/attributes.py
@@ -17,3 +17,14 @@ def attributes_values_with_empty(variant, attributes):
else:
values.append(ATTRIBUTE_EMPTY_VALUE)
return values
+
+
+def get_object_properties(object, properties):
+ """Returns first non empty property of given object."""
+ properties = properties.split(',')
+ for property in properties:
+ attribute = getattr(object, property, '')
+ if attribute:
+ return attribute
+ return ''
diff --git a/templates/product/details.html b/templates/product/details.html
index 5dad950f16..61b1e89a7b 100644
--- a/templates/product/details.html
+++ b/templates/product/details.html
@@ -9,6 +9,7 @@
{% load get_thumbnail product_first_image from product_images %}
{% load build_absolute_uri from urls %}
{% load placeholder %}
+{% load get_object_properties from attributes %}
{% block title %}
{% if product.seo_title %}
@@ -20,8 +21,8 @@
{% block meta_tags %}
<meta property="og:title" content="{{ product.seo_title|default:product.name }}">
- <meta property="og:description" content="{{ product.seo_description|default:product.description }}">
- <meta name="description" content="{{ product.seo_description|default:product.description }}">
+ <meta property="og:description" content="{{ product.seo_description|default:"" }}">
+ <meta name="description" content="{{ product.seo_description|default:"" }}">
{% build_absolute_uri request=request location=product.get_absolute_url as product_url %}
<meta property="og:url" content="{{ product_url }}">
diff --git a/templates/product/product_list_base.html b/templates/product/product_list_base.html
index 9bdcf23b0c..7dbdf05c72 100644
--- a/templates/product/product_list_base.html
+++ b/templates/product/product_list_base.html
@@ -5,6 +5,7 @@
{% load staticfiles %}
{% load prices_i18n %}
{% load build_absolute_uri from urls %}
+{% load get_object_properties from attributes %}
{% block footer_scripts %}
{{ block.super }}
@@ -20,14 +21,9 @@
{% block meta_tags %}
<meta property="og:title" content="{{ object.seo_title|default:object.name }}">
-
- <meta name="description" content="
- {% if object.seo_description %}
- {{ object.seo_description }}
- {% elif object.description %}
- {{ object.description }}
- {% endif %}
- ">
+ {% get_object_properties object=object properties="seo_description,description" as seo_description %}
+ <meta property="og:description" content="{{ seo_description }}">
+ <meta name="description" content="{{ seo_description }}">
<meta property="og:image" content="{% static "images/block1.png" %}">
{% build_absolute_uri request=request location=object.get_absolute_url as object_url %}