0001-wcs-format-text-fields-content-like-wcs-56422.patch
combo/apps/wcs/templates/combo/wcs/card-field-value.html | ||
---|---|---|
1 |
{% spaceless %} |
|
1 |
{% load wcs %}{% spaceless %} |
|
2 |
{% if field.type == "text" and mode != 'inline' and value %} |
|
3 |
<div class="value">{{ field|format_text:value }}</div> |
|
4 |
{% else %} |
|
5 |
{% if not mode == 'inline' %}<span class="value">{% endif %} |
|
2 | 6 |
{% if field.type == "date" %} |
3 | 7 |
{{ value|date }} |
4 | 8 |
{% elif field.type == "bool" and value is not None %} |
... | ... | |
6 | 10 |
{% else %} |
7 | 11 |
{{ value|default:"" }} |
8 | 12 |
{% endif %} |
13 |
{% if not mode == 'inline' %}</span>{% endif %} |
|
14 |
{% endif %} |
|
9 | 15 |
{% endspaceless %} |
combo/apps/wcs/templates/combo/wcs/card.html | ||
---|---|---|
18 | 18 |
{% if field.varname == item.varname %} |
19 | 19 |
{% with card.fields|get:item.varname as value %} |
20 | 20 |
{% if item.display_mode == "title" %} |
21 |
<h3>{% include "combo/wcs/card-field-value.html" %}</h3> |
|
21 |
<h3>{% include "combo/wcs/card-field-value.html" with mode="inline" %}</h3>
|
|
22 | 22 |
{% endif %} |
23 | 23 |
{% if item.display_mode == "label" or item.display_mode == "label-and-value" %} |
24 | 24 |
<p class="label">{{ field.label }}</p> |
25 | 25 |
{% endif %} |
26 | 26 |
{% if item.display_mode == "value" or item.display_mode == "label-and-value" %} |
27 |
<p class="value"> |
|
28 |
{% include "combo/wcs/card-field-value.html" %} |
|
29 |
</p> |
|
27 |
{% include "combo/wcs/card-field-value.html" %} |
|
30 | 28 |
{% endif %} |
31 | 29 |
{% endwith %} |
32 | 30 |
{% endif %} |
... | ... | |
39 | 37 |
{% for field in schema.fields %} |
40 | 38 |
{% if 'varname' in field and field.varname and field.type != 'file' %} |
41 | 39 |
{% with card.fields|get:field.varname as value %} |
42 |
<p>
|
|
40 |
<div class="card--auto-field">
|
|
43 | 41 |
<span class="label">{{ field.label }}</span> |
44 |
<span class="value">{% include "combo/wcs/card-field-value.html" %}</span>
|
|
45 |
</p>
|
|
42 |
{% include "combo/wcs/card-field-value.html" %}
|
|
43 |
</div>
|
|
46 | 44 |
{% endwith %} |
47 | 45 |
{% endif %} |
48 | 46 |
{% endfor %} |
combo/apps/wcs/templatetags/wcs.py | ||
---|---|---|
15 | 15 |
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
16 | 16 | |
17 | 17 |
from django import template |
18 |
from django.utils.html import escape |
|
19 |
from django.utils.safestring import mark_safe |
|
18 | 20 | |
19 | 21 |
register = template.Library() |
20 | 22 | |
... | ... | |
62 | 64 |
@register.filter |
63 | 65 |
def filter_by_status(queryset, status): |
64 | 66 |
return queryset.filter_by_status(status) |
67 | ||
68 | ||
69 |
@register.filter |
|
70 |
def format_text(field, value): |
|
71 |
if field.get('pre'): |
|
72 |
return mark_safe('<pre>%s</pre>' % escape(value)) |
|
73 |
return mark_safe('<p>' + '\n'.join([(escape(x) or '</p><p>') for x in value.splitlines()]) + '</p>') |
tests/test_wcs.py | ||
---|---|---|
182 | 182 |
{'label': 'Field B', 'varname': 'fieldb', 'type': 'bool'}, |
183 | 183 |
{'label': 'Field C', 'varname': 'fieldc', 'type': 'date'}, |
184 | 184 |
{'label': 'Field D', 'varname': 'fieldd', 'type': 'file'}, |
185 |
{'label': 'Field E', 'varname': 'fielde', 'type': 'text'}, |
|
186 |
{'label': 'Field F', 'varname': 'fieldf', 'type': 'text', 'pre': True}, |
|
185 | 187 |
{'label': 'Related', 'varname': 'related', 'type': 'item'}, |
186 | 188 |
{'label': 'Page', 'type': 'page'}, |
187 | 189 |
{'label': 'Comment', 'type': 'comment'}, |
... | ... | |
203 | 205 |
'fieldb': True, |
204 | 206 |
'fieldc': '2020-09-28', |
205 | 207 |
'fieldd': {'filename': 'file.pdf', 'url': 'http://some-url.com/download?f=42'}, |
208 |
'fielde': 'lorem<strong>ipsum\n\nhello world', |
|
209 |
'fieldf': 'lorem<strong>ipsum\n\nhello world', |
|
206 | 210 |
'related': 'Foo Bar', |
207 | 211 |
'related_raw': 42, |
208 | 212 |
'related_structured': {'id': 42, 'text': 'blah'}, |
... | ... | |
1815 | 1819 |
assert '<h2>Card Model 1 - aa</h2>' in result # template error, default value |
1816 | 1820 | |
1817 | 1821 | |
1822 |
@mock.patch('combo.apps.wcs.utils.requests.send', side_effect=mocked_requests_send) |
|
1823 |
def test_card_cell_render_text_field(mock_send, context): |
|
1824 |
page = Page.objects.create(title='xxx', template_name='standard') |
|
1825 |
cell = WcsCardInfosCell(page=page, placeholder='content', order=0) |
|
1826 |
cell.carddef_reference = 'default:card_model_1' |
|
1827 |
cell.custom_title = 'Foo bar {{ card.fields.title }}' |
|
1828 |
cell.save() |
|
1829 | ||
1830 |
context['card_model_1_id'] = 11 |
|
1831 |
context['synchronous'] = True # to get fresh content |
|
1832 | ||
1833 |
result = cell.render(context) |
|
1834 | ||
1835 |
# field E is split in paragraphs |
|
1836 |
assert ( |
|
1837 |
PyQuery(result).find('span.label:contains("Field E") + div.value p:first-child').text().strip() |
|
1838 |
== 'lorem<strong>ipsum' |
|
1839 |
) |
|
1840 |
assert ( |
|
1841 |
PyQuery(result).find('span.label:contains("Field E") + div.value p:last-child').text().strip() |
|
1842 |
== 'hello world' |
|
1843 |
) |
|
1844 | ||
1845 |
# field F is put in a <pre> |
|
1846 |
assert ( |
|
1847 |
PyQuery(result).find('span.label:contains("Field F") + div.value pre').text() |
|
1848 |
== 'lorem<strong>ipsum hello world' |
|
1849 |
) |
|
1850 | ||
1851 | ||
1818 | 1852 |
@mock.patch('combo.apps.wcs.utils.requests.send', side_effect=mocked_requests_send) |
1819 | 1853 |
def test_card_cell_render_identifier(mock_send, context, nocache): |
1820 | 1854 |
page = Page.objects.create(title='xxx', template_name='standard') |
1821 |
- |