Projet

Général

Profil

0004-wcs-add-subtitle-display-mode-for-card-cell-custom-s.patch

Lauréline Guérin, 10 janvier 2022 14:11

Télécharger (4,73 ko)

Voir les différences:

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(-)
combo/apps/wcs/templates/combo/wcs/card.html
19 19
        {% if item.varname == "@custom@" and item.template %}
20 20
          {% with card.custom_fields|get:item.template|force_escape as value %}
21 21
          {% if item.display_mode == "title" %}
22
          <h3>{{ value }}</h3>
22
            <h3>{{ value }}</h3>
23
          {% elif item.display_mode == "subtitle" %}
24
            <h4>{{ value }}</h4>
23 25
          {% elif item.display_mode == "label" %}
24 26
            <p class="label">{{ value }}</p>
25 27
          {% elif item.display_mode == "text" %}
......
35 37
              {% elif item.field_content == "value" %}
36 38
              <h3>{% include "combo/wcs/card-field-value.html" with mode="inline" %}</h3>
37 39
              {% endif %}
40
            {% elif item.display_mode == "subtitle" %}
41
              {% if item.field_content == "label" %}
42
              <h4>{{ field.label }}</h4>
43
              {% elif item.field_content == "value" %}
44
              <h4>{% include "combo/wcs/card-field-value.html" with mode="inline" %}</h4>
45
              {% endif %}
38 46
            {% elif item.display_mode == "text" %}
39 47
              {% if item.field_content == "label" or item.field_content == "label-and-value" %}
40 48
                <p class="label">{{ field.label }}</p>
combo/apps/wcs/templates/combo/wcs/manager/card-infos-cell-form.html
69 69
        <select name="field_display_mode" data-dynamic-display-child-of="entry_type" data-dynamic-display-value="@field@">
70 70
          <option value="text">{% trans "Text" %}</option>
71 71
          <option value="title">{% trans "Title" %}</option>
72
          <option value="subtitle">{% trans "Subtitle" %}</option>
72 73
        </select>
73 74
      </label>
74 75
    </p>
......
85 86
          <option value="label">{% trans "Label" %}</option>
86 87
          <option value="text">{% trans "Text" %}</option>
87 88
          <option value="title">{% trans "Title" %}</option>
89
          <option value="subtitle">{% trans "Subtitle" %}</option>
88 90
        </select>
89 91
      </label>
90 92
    </p>
tests/test_wcs.py
2090 2090
    result = cell.render(context)
2091 2091
    assert PyQuery(result).find('h3').text() == 'a'
2092 2092

  
2093
    cell.custom_schema['cells'][0] = {
2094
        'varname': 'fielda',
2095
        'field_content': 'value',
2096
        'display_mode': 'subtitle',
2097
    }
2098
    cell.save()
2099
    result = cell.render(context)
2100
    assert PyQuery(result).find('h4').text() == 'a'
2101

  
2093 2102
    cell.custom_schema['cells'][0] = {'varname': 'fielda', 'field_content': 'label', 'display_mode': 'title'}
2094 2103
    cell.save()
2095 2104
    result = cell.render(context)
2096 2105
    assert PyQuery(result).find('h3').text() == 'Field A'
2097 2106

  
2107
    cell.custom_schema['cells'][0] = {
2108
        'varname': 'fielda',
2109
        'field_content': 'label',
2110
        'display_mode': 'subtitle',
2111
    }
2112
    cell.save()
2113
    result = cell.render(context)
2114
    assert PyQuery(result).find('h4').text() == 'Field A'
2115

  
2098 2116
    cell.custom_schema['cells'][0] = {'varname': 'fielda', 'field_content': 'label', 'display_mode': 'text'}
2099 2117
    cell.save()
2100 2118
    result = cell.render(context)
......
2228 2246
    cell.custom_schema['cells'][0][
2229 2247
        'template'
2230 2248
    ] = '{{ card.fields.fielda }} - {{ card.fields.related }} ({{ card.fields.related_structured.id }})'
2249
    cell.custom_schema['cells'][0]['display_mode'] = 'subtitle'
2231 2250
    cell.save()
2232 2251
    result = cell.render(context)
2233
    assert PyQuery(result).find('h3').text() == 'a - Foo Bar (42)'
2252
    assert PyQuery(result).find('h4').text() == 'a - Foo Bar (42)'
2234 2253

  
2235 2254
    # test display_mode & filters in template
2236 2255
    cell.custom_schema = {
2237
-