From ebab8fdb4e50b3867828d7f59ca5120889c8654d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Laur=C3=A9line=20Gu=C3=A9rin?= Date: Tue, 26 Apr 2022 10:05:18 +0200 Subject: [PATCH] wcs: don't add cell's div if empty value have to be skipped (#64451) --- .../wcs/templates/combo/wcs/card-field-as-title.html | 6 ++---- combo/apps/wcs/templates/combo/wcs/card.html | 12 +++++++++--- tests/test_wcs.py | 6 ++++++ 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/combo/apps/wcs/templates/combo/wcs/card-field-as-title.html b/combo/apps/wcs/templates/combo/wcs/card-field-as-title.html index 9a562200..8478420d 100644 --- a/combo/apps/wcs/templates/combo/wcs/card-field-as-title.html +++ b/combo/apps/wcs/templates/combo/wcs/card-field-as-title.html @@ -1,11 +1,9 @@ {% if item.field_content == "label" %} - {% if value or item.empty_value != '@skip@' %} - <{{ title_tag }}>{{ field.label }} - {% endif %} + <{{ title_tag }}>{{ field.label }} {% elif item.field_content == "value" %} {% if value or item.empty_value == '@empty@' %} <{{ title_tag }}>{% include "combo/wcs/card-field-value.html" with mode="inline" %} - {% elif item.empty_value != '@skip@' and item.empty_value != '@empty@' %} + {% else %} {% with item.empty_value as value %} <{{ title_tag }}>{% include "combo/wcs/card-field-value.html" with mode="inline" %} {% endwith %} diff --git a/combo/apps/wcs/templates/combo/wcs/card.html b/combo/apps/wcs/templates/combo/wcs/card.html index 16085ffd..513d14f8 100644 --- a/combo/apps/wcs/templates/combo/wcs/card.html +++ b/combo/apps/wcs/templates/combo/wcs/card.html @@ -16,8 +16,8 @@ {% with cell.get_custom_schema as custom_schema %}
{% for item in custom_schema.cells %} -
{% if item.varname == "@custom@" and item.template %} +
{% with card.custom_fields|get:item.template|force_escape as value %} {% if item.display_mode == "title" %}

{{ value }}

@@ -29,14 +29,19 @@
{{ value }}
{% endif %} {% endwith %} +
{% elif item.varname == "@link@" and item.url_template and item.template %} +
{% with card.custom_fields|get:item.template|force_escape as link_label and card.urls|get:item.url_template|force_escape as link_url %} {% endwith %} +
{% else %} {% with fields_by_varnames|get:item.varname as field %} {% if field %} {% with card.fields|get:item.varname as value %} + {% if value or item.empty_value != '@skip@' %} +
{% if item.display_mode == "title" %} {% include "combo/wcs/card-field-as-title.html" with title_tag="h3" %} {% elif item.display_mode == "subtitle" %} @@ -44,17 +49,18 @@ {% elif item.display_mode == "text" %} {% if value or item.empty_value == '@empty@' %} {% include "combo/wcs/card-field-as-text.html" %} - {% elif item.empty_value != '@skip@' and item.empty_value != '@empty@' %} + {% else %} {% with item.empty_value as value %} {% include "combo/wcs/card-field-as-text.html" %} {% endwith %} {% endif %} {% endif %} +
+ {% endif %} {% endwith %} {% endif %} {% endwith %} {% endif %} -
{% endfor%}
{% endwith %} diff --git a/tests/test_wcs.py b/tests/test_wcs.py index 74c861ae..e03bc54e 100644 --- a/tests/test_wcs.py +++ b/tests/test_wcs.py @@ -2897,6 +2897,7 @@ def test_card_cell_render_custom_schema_card_empty_field(mock_send, context): context['synchronous'] = True # to get fresh content result = cell.render(context) + assert len(PyQuery(result).find('.cell--body > div > div')) == 0 assert PyQuery(result).find('.label') == [] assert PyQuery(result).find('.value') == [] @@ -2908,6 +2909,7 @@ def test_card_cell_render_custom_schema_card_empty_field(mock_send, context): } cell.save() result = cell.render(context) + assert len(PyQuery(result).find('.cell--body > div > div')) == 1 assert PyQuery(result).find('.label').text() == 'Empty' assert PyQuery(result).find('.value').text() == '' @@ -2919,6 +2921,7 @@ def test_card_cell_render_custom_schema_card_empty_field(mock_send, context): } cell.save() result = cell.render(context) + assert len(PyQuery(result).find('.cell--body > div > div')) == 1 assert PyQuery(result).find('.label').text() == 'Empty' assert PyQuery(result).find('.value').text() == 'Custom text' @@ -2940,6 +2943,7 @@ def test_card_cell_render_custom_schema_card_empty_field(mock_send, context): } cell.save() result = cell.render(context) + assert len(PyQuery(result).find('.cell--body > div > div')) == 0 assert PyQuery(result).find(html_tag) == [] cell.custom_schema['cells'][0] = { @@ -2950,6 +2954,7 @@ def test_card_cell_render_custom_schema_card_empty_field(mock_send, context): } cell.save() result = cell.render(context) + assert len(PyQuery(result).find('.cell--body > div > div')) == 1 assert PyQuery(result).find(html_tag).text() == ('Empty' if field_content == 'label' else '') cell.custom_schema['cells'][0] = { @@ -2960,6 +2965,7 @@ def test_card_cell_render_custom_schema_card_empty_field(mock_send, context): } cell.save() result = cell.render(context) + assert len(PyQuery(result).find('.cell--body > div > div')) == 1 assert PyQuery(result).find(html_tag).text() == ( 'Empty' if field_content == 'label' else 'Custom text' )