wcs: display email fields as mailto: links (#57954)

This commit is contained in:
Frédéric Péters 2021-11-11 11:47:37 +01:00
parent 8f02cb2fc2
commit f8138782f1
2 changed files with 25 additions and 0 deletions

View File

@ -7,6 +7,8 @@
{{ value|date }}
{% elif field.type == "bool" and value is not None %}
{{ value|yesno }}
{% elif field.type == "email" and value is not None %}
<a href="mailto:{{ value }}">{{ value }}</a>
{% elif field.type == 'file' and value %}
{% if value.content_type|startswith:"image/" %}
<img alt="" src="{% make_public_url url=value.url %}">

View File

@ -176,6 +176,7 @@ WCS_CARDDEF_SCHEMA = {
{'label': 'Field D', 'varname': 'fieldd', 'type': 'file'},
{'label': 'Field E', 'varname': 'fielde', 'type': 'text'},
{'label': 'Field F', 'varname': 'fieldf', 'type': 'text', 'pre': True},
{'label': 'Field G', 'varname': 'fieldg', 'type': 'email'},
{'label': 'Related', 'varname': 'related', 'type': 'item'},
{'label': 'Page', 'type': 'page'},
{'label': 'Comment', 'type': 'comment'},
@ -199,6 +200,7 @@ WCS_CARD_DATA = {
'fieldd': {'filename': 'file.pdf', 'url': 'http://127.0.0.1:8999/download?f=42'},
'fielde': 'lorem<strong>ipsum\n\nhello world',
'fieldf': 'lorem<strong>ipsum\n\nhello world',
'fieldg': 'test@localhost',
'related': 'Foo Bar',
'related_raw': 42,
'related_structured': {'id': 42, 'text': 'blah'},
@ -1903,6 +1905,27 @@ def test_card_cell_render_text_field(mock_send, context):
)
@mock.patch('combo.apps.wcs.utils.requests.send', side_effect=mocked_requests_send)
def test_card_cell_render_email_field(mock_send, context):
page = Page.objects.create(title='xxx', template_name='standard')
cell = WcsCardInfosCell(page=page, placeholder='content', order=0)
cell.carddef_reference = 'default:card_model_1'
cell.custom_title = 'Foo bar {{ card.fields.title }}'
cell.save()
context['card_model_1_id'] = 11
context['synchronous'] = True # to get fresh content
result = cell.render(context)
assert PyQuery(result).find('span.label:contains("Field G") + .value a').text() == 'test@localhost'
assert (
PyQuery(result).find('span.label:contains("Field G") + .value a').attr['href']
== 'mailto:test@localhost'
)
@mock.patch('combo.apps.wcs.utils.requests.send', side_effect=mocked_requests_send)
def test_card_cell_render_identifier(mock_send, context, nocache):
page = Page.objects.create(title='xxx', template_name='standard')