From 7b22e5bebcf8eb3de4c69314030416fb4ecc09c3 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Laur=C3=A9line=20Gu=C3=A9rin?= <zebuline@entrouvert.com>
Date: Thu, 6 Jan 2022 16:57:34 +0100
Subject: [PATCH 4/4] wcs: add subtitle display mode for card cell custom
 schema (#60369)

---
 combo/apps/wcs/templates/combo/wcs/card.html  | 10 ++++++++-
 .../wcs/manager/card-infos-cell-form.html     |  2 ++
 tests/test_wcs.py                             | 21 ++++++++++++++++++-
 3 files changed, 31 insertions(+), 2 deletions(-)

diff --git a/combo/apps/wcs/templates/combo/wcs/card.html b/combo/apps/wcs/templates/combo/wcs/card.html
index f44429b1..f3b7bd32 100644
--- a/combo/apps/wcs/templates/combo/wcs/card.html
+++ b/combo/apps/wcs/templates/combo/wcs/card.html
@@ -19,7 +19,9 @@
         {% if item.varname == "@custom@" and item.template %}
           {% with card.custom_fields|get:item.template|force_escape as value %}
           {% if item.display_mode == "title" %}
-          <h3>{{ value }}</h3>
+            <h3>{{ value }}</h3>
+          {% elif item.display_mode == "subtitle" %}
+            <h4>{{ value }}</h4>
           {% elif item.display_mode == "label" %}
             <p class="label">{{ value }}</p>
           {% elif item.display_mode == "text" %}
@@ -35,6 +37,12 @@
               {% elif item.field_content == "value" %}
               <h3>{% include "combo/wcs/card-field-value.html" with mode="inline" %}</h3>
               {% endif %}
+            {% elif item.display_mode == "subtitle" %}
+              {% if item.field_content == "label" %}
+              <h4>{{ field.label }}</h4>
+              {% elif item.field_content == "value" %}
+              <h4>{% include "combo/wcs/card-field-value.html" with mode="inline" %}</h4>
+              {% endif %}
             {% elif item.display_mode == "text" %}
               {% if item.field_content == "label" or item.field_content == "label-and-value" %}
                 <p class="label">{{ field.label }}</p>
diff --git a/combo/apps/wcs/templates/combo/wcs/manager/card-infos-cell-form.html b/combo/apps/wcs/templates/combo/wcs/manager/card-infos-cell-form.html
index 441c207a..aa9f5bb9 100644
--- a/combo/apps/wcs/templates/combo/wcs/manager/card-infos-cell-form.html
+++ b/combo/apps/wcs/templates/combo/wcs/manager/card-infos-cell-form.html
@@ -68,6 +68,7 @@
         {% trans "Display mode" %}
         <select name="field_display_mode" data-dynamic-display-child-of="entry_type" data-dynamic-display-value="@field@">
           <option value="title">{% trans "Title" %}</option>
+          <option value="subtitle">{% trans "Subtitle" %}</option>
           <option value="text">{% trans "Text" %}</option>
         </select>
       </label>
@@ -83,6 +84,7 @@
         {% trans "Display mode" %}
         <select name="custom_display_mode" data-dynamic-display-child-of="entry_type" data-dynamic-display-value="@custom@">
           <option value="title">{% trans "Title" %}</option>
+          <option value="subtitle">{% trans "Subtitle" %}</option>
           <option value="label">{% trans "Label" %}</option>
           <option value="text">{% trans "Text" %}</option>
         </select>
diff --git a/tests/test_wcs.py b/tests/test_wcs.py
index 4274f85f..2ccd9d27 100644
--- a/tests/test_wcs.py
+++ b/tests/test_wcs.py
@@ -2092,11 +2092,29 @@ def test_card_cell_render_custom_schema_card_field(mock_send, context):
     result = cell.render(context)
     assert PyQuery(result).find('h3').text() == 'a'
 
+    cell.custom_schema['cells'][0] = {
+        'varname': 'fielda',
+        'field_content': 'value',
+        'display_mode': 'subtitle',
+    }
+    cell.save()
+    result = cell.render(context)
+    assert PyQuery(result).find('h4').text() == 'a'
+
     cell.custom_schema['cells'][0] = {'varname': 'fielda', 'field_content': 'label', 'display_mode': 'title'}
     cell.save()
     result = cell.render(context)
     assert PyQuery(result).find('h3').text() == 'Field A'
 
+    cell.custom_schema['cells'][0] = {
+        'varname': 'fielda',
+        'field_content': 'label',
+        'display_mode': 'subtitle',
+    }
+    cell.save()
+    result = cell.render(context)
+    assert PyQuery(result).find('h4').text() == 'Field A'
+
     cell.custom_schema['cells'][0] = {'varname': 'fielda', 'field_content': 'label', 'display_mode': 'text'}
     cell.save()
     result = cell.render(context)
@@ -2230,9 +2248,10 @@ def test_card_cell_render_custom_schema_custom_entry(mock_send, context, app):
     cell.custom_schema['cells'][0][
         'template'
     ] = '{{ card.fields.fielda }} - {{ card.fields.related }} ({{ card.fields.related_structured.id }})'
+    cell.custom_schema['cells'][0]['display_mode'] = 'subtitle'
     cell.save()
     result = cell.render(context)
-    assert PyQuery(result).find('h3').text() == 'a - Foo Bar (42)'
+    assert PyQuery(result).find('h4').text() == 'a - Foo Bar (42)'
 
     # test display_mode & filters in template
     cell.custom_schema = {
-- 
2.34.1

