wcs: fix email field with empty value (#73877)
This commit is contained in:
parent
292c1c74e3
commit
9fd735cf11
|
@ -2,5 +2,5 @@
|
|||
<div class="label">{{ field.label }}</div>
|
||||
{% endif %}
|
||||
{% if item.field_content == "value" or item.field_content == "label-and-value" %}
|
||||
{% include "combo/wcs/card-field-value.html" %}
|
||||
{% include "combo/wcs/card-field-value.html" with empty=empty %}
|
||||
{% endif %}
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
{{ value|date }}
|
||||
{% elif field.type == "bool" and value is not None %}
|
||||
{{ value|yesno }}
|
||||
{% elif field.type == "email" and value is not None %}
|
||||
{% elif field.type == "email" and value is not None and not empty %}
|
||||
<a class="pk-card-field-email" href="mailto:{{ value }}">{{ value }}</a>
|
||||
{% elif field.type == 'file' and value %}
|
||||
{% if value.content_type|startswith:"image/" %}
|
||||
|
|
|
@ -73,7 +73,7 @@
|
|||
{% include "combo/wcs/card-field-as-text.html" %}
|
||||
{% else %}
|
||||
{% with item.empty_value as value %}
|
||||
{% include "combo/wcs/card-field-as-text.html" %}
|
||||
{% include "combo/wcs/card-field-as-text.html" with empty=True %}
|
||||
{% endwith %}
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
|
|
|
@ -36,7 +36,7 @@
|
|||
{% if field and value %}
|
||||
{% if not ul_display %}<td>{% endif %}{% include "combo/wcs/card-field-value.html" with mode='inline' %}{% if not ul_display %}</td>{% endif %}
|
||||
{% elif field %}
|
||||
{% if not ul_display %}<td>{% endif %}{% include "combo/wcs/card-field-value.html" with mode='inline' value=item.empty_value %}{% if not ul_display %}</td>{% endif %}
|
||||
{% if not ul_display %}<td>{% endif %}{% include "combo/wcs/card-field-value.html" with mode='inline' value=item.empty_value empty=True %}{% if not ul_display %}</td>{% endif %}
|
||||
{% endif %}
|
||||
{% endwith %}
|
||||
{% endif %}
|
||||
|
|
|
@ -951,6 +951,7 @@ def test_card_cell_table_mode_render_custom_schema_card_empty_field(mock_send, c
|
|||
else:
|
||||
assert PyQuery(result).find('table tr td') == []
|
||||
assert PyQuery(result).find('ul li:first-child').text() == value
|
||||
return result
|
||||
|
||||
test('')
|
||||
|
||||
|
@ -961,6 +962,24 @@ def test_card_cell_table_mode_render_custom_schema_card_empty_field(mock_send, c
|
|||
cell.save()
|
||||
test('Custom text')
|
||||
|
||||
cell.custom_schema['cells'][0] = {
|
||||
'varname': 'empty_email',
|
||||
'empty_value': '',
|
||||
}
|
||||
cell.save()
|
||||
result = test('')
|
||||
assert PyQuery(result).find('table tr:first-child td:first-child a') == []
|
||||
assert PyQuery(result).find('ul li:first-child a') == []
|
||||
|
||||
cell.custom_schema['cells'][0] = {
|
||||
'varname': 'empty_email',
|
||||
'empty_value': 'Custom text',
|
||||
}
|
||||
cell.save()
|
||||
result = test('Custom text')
|
||||
assert PyQuery(result).find('table tr:first-child td:first-child a') == []
|
||||
assert PyQuery(result).find('ul li:first-child a') == []
|
||||
|
||||
|
||||
@mock.patch('requests.Session.send', side_effect=mocked_requests_send)
|
||||
@pytest.mark.parametrize('nb_cells', [1, 2])
|
||||
|
@ -1998,6 +2017,19 @@ def test_card_cell_card_mode_render_custom_schema_card_empty_field(mock_send, co
|
|||
'Empty' if field_content == 'label' else 'Custom text'
|
||||
)
|
||||
|
||||
cell.custom_schema['cells'][0] = {
|
||||
'varname': 'empty_email',
|
||||
'field_content': 'label-and-value',
|
||||
'display_mode': 'text',
|
||||
'empty_value': 'Custom text',
|
||||
}
|
||||
cell.save()
|
||||
result = cell.render(context)
|
||||
assert len(PyQuery(result).find('.cell--body > div > div')) == 1
|
||||
assert PyQuery(result).find('.label').text() == 'Empty Email'
|
||||
assert PyQuery(result).find('.value').text() == 'Custom text'
|
||||
assert PyQuery(result).find('.value a') == []
|
||||
|
||||
|
||||
@mock.patch('requests.Session.send', side_effect=mocked_requests_send)
|
||||
def test_card_cell_card_mode_render_custom_schema_custom_entry(mock_send, context, app):
|
||||
|
|
|
@ -246,6 +246,7 @@ WCS_CARDDEF_SCHEMAS = {
|
|||
{'label': 'Field H', 'varname': 'fieldh', 'type': 'string'},
|
||||
{'label': 'Field I', 'varname': 'fieldi', 'type': 'text', 'display_mode': 'rich'},
|
||||
{'label': 'Empty', 'varname': 'empty', 'type': 'string'},
|
||||
{'label': 'Empty Email', 'varname': 'empty_email', 'type': 'email'},
|
||||
{'label': 'Related', 'varname': 'related', 'type': 'item'},
|
||||
{'label': 'Page', 'type': 'page'},
|
||||
{'label': 'Comment', 'type': 'comment'},
|
||||
|
|
Loading…
Reference in New Issue