wcs: don't add cell's div if empty value have to be skipped (#64451)
gitea-wip/combo/pipeline/head There was a failure building this commit Details
gitea/combo/pipeline/head Something is wrong with the build of this commit Details

This commit is contained in:
Lauréline Guérin 2022-04-26 10:05:18 +02:00
parent 096d396c84
commit ebab8fdb4e
No known key found for this signature in database
GPG Key ID: 1FAB9B9B4F93D473
3 changed files with 17 additions and 7 deletions

View File

@ -1,11 +1,9 @@
{% if item.field_content == "label" %}
{% if value or item.empty_value != '@skip@' %}
<{{ title_tag }}>{{ field.label }}</{{ title_tag }}>
{% endif %}
<{{ title_tag }}>{{ field.label }}</{{ title_tag }}>
{% elif item.field_content == "value" %}
{% if value or item.empty_value == '@empty@' %}
<{{ title_tag }}>{% include "combo/wcs/card-field-value.html" with mode="inline" %}</{{ title_tag }}>
{% 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" %}</{{ title_tag }}>
{% endwith %}

View File

@ -16,8 +16,8 @@
{% with cell.get_custom_schema as custom_schema %}
<div class="{{ custom_schema.grid_class }}">
{% for item in custom_schema.cells %}
<div class="{{ item.cell_size|default:"" }}">
{% if item.varname == "@custom@" and item.template %}
<div class="{{ item.cell_size|default:"" }}">
{% with card.custom_fields|get:item.template|force_escape as value %}
{% if item.display_mode == "title" %}
<h3>{{ value }}</h3>
@ -29,14 +29,19 @@
<div class="value">{{ value }}</div>
{% endif %}
{% endwith %}
</div>
{% elif item.varname == "@link@" and item.url_template and item.template %}
<div class="{{ item.cell_size|default:"" }}">
{% with card.custom_fields|get:item.template|force_escape as link_label and card.urls|get:item.url_template|force_escape as link_url %}
<div class="value"><a href="{{ link_url }}"{% if item.display_mode == 'button' %} class="pk-button"{% endif %}>{{ link_label }}</a></div>
{% endwith %}
</div>
{% 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@' %}
<div class="{{ item.cell_size|default:"" }}">
{% 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 %}
</div>
{% endif %}
{% endwith %}
{% endif %}
{% endwith %}
{% endif %}
</div>
{% endfor%}
</div>
{% endwith %}

View File

@ -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'
)