Projet

Général

Profil

0001-wcs-don-t-add-cell-s-div-if-empty-value-have-to-be-s.patch

Lauréline Guérin, 26 avril 2022 10:06

Télécharger (6,33 ko)

Voir les différences:

Subject: [PATCH] wcs: don't add cell's div if empty value have to be skipped
 (#64451)

 .../wcs/templates/combo/wcs/card-field-as-title.html |  6 ++----
 combo/apps/wcs/templates/combo/wcs/card.html         | 12 +++++++++---
 tests/test_wcs.py                                    |  6 ++++++
 3 files changed, 17 insertions(+), 7 deletions(-)
combo/apps/wcs/templates/combo/wcs/card-field-as-title.html
1 1
{% if item.field_content == "label" %}
2
  {% if value or item.empty_value != '@skip@' %}
3
    <{{ title_tag }}>{{ field.label }}</{{ title_tag }}>
4
  {% endif %}
2
  <{{ title_tag }}>{{ field.label }}</{{ title_tag }}>
5 3
{% elif item.field_content == "value" %}
6 4
  {% if value or item.empty_value == '@empty@' %}
7 5
    <{{ title_tag }}>{% include "combo/wcs/card-field-value.html" with mode="inline" %}</{{ title_tag }}>
8
  {% elif item.empty_value != '@skip@' and item.empty_value != '@empty@' %}
6
  {% else %}
9 7
    {% with item.empty_value as value %}
10 8
      <{{ title_tag }}>{% include "combo/wcs/card-field-value.html" with mode="inline" %}</{{ title_tag }}>
11 9
    {% endwith %}
combo/apps/wcs/templates/combo/wcs/card.html
16 16
  {% with cell.get_custom_schema as custom_schema %}
17 17
  <div class="{{ custom_schema.grid_class }}">
18 18
    {% for item in custom_schema.cells %}
19
      <div class="{{ item.cell_size|default:"" }}">
20 19
        {% if item.varname == "@custom@" and item.template %}
20
        <div class="{{ item.cell_size|default:"" }}">
21 21
          {% with card.custom_fields|get:item.template|force_escape as value %}
22 22
          {% if item.display_mode == "title" %}
23 23
            <h3>{{ value }}</h3>
......
29 29
            <div class="value">{{ value }}</div>
30 30
          {% endif %}
31 31
          {% endwith %}
32
        </div>
32 33
        {% elif item.varname == "@link@" and item.url_template and item.template %}
34
        <div class="{{ item.cell_size|default:"" }}">
33 35
          {% with card.custom_fields|get:item.template|force_escape as link_label and card.urls|get:item.url_template|force_escape as link_url %}
34 36
          <div class="value"><a href="{{ link_url }}"{% if item.display_mode == 'button' %} class="pk-button"{% endif %}>{{ link_label }}</a></div>
35 37
          {% endwith %}
38
        </div>
36 39
        {% else %}
37 40
          {% with fields_by_varnames|get:item.varname as field %}
38 41
          {% if field %}
39 42
          {% with card.fields|get:item.varname as value %}
43
          {% if value or item.empty_value != '@skip@' %}
44
          <div class="{{ item.cell_size|default:"" }}">
40 45
            {% if item.display_mode == "title" %}
41 46
              {% include "combo/wcs/card-field-as-title.html" with title_tag="h3" %}
42 47
            {% elif item.display_mode == "subtitle" %}
......
44 49
            {% elif item.display_mode == "text" %}
45 50
              {% if value or item.empty_value == '@empty@' %}
46 51
                {% include "combo/wcs/card-field-as-text.html" %}
47
              {% elif item.empty_value != '@skip@' and item.empty_value != '@empty@' %}
52
              {% else %}
48 53
                {% with item.empty_value as value %}
49 54
                  {% include "combo/wcs/card-field-as-text.html" %}
50 55
                {% endwith %}
51 56
              {% endif %}
52 57
            {% endif %}
58
          </div>
59
          {% endif %}
53 60
          {% endwith %}
54 61
          {% endif %}
55 62
          {% endwith %}
56 63
        {% endif %}
57
      </div>
58 64
    {% endfor%}
59 65
  </div>
60 66
  {% endwith %}
tests/test_wcs.py
2861 2861
    context['synchronous'] = True  # to get fresh content
2862 2862

  
2863 2863
    result = cell.render(context)
2864
    assert len(PyQuery(result).find('.cell--body > div > div')) == 0
2864 2865
    assert PyQuery(result).find('.label') == []
2865 2866
    assert PyQuery(result).find('.value') == []
2866 2867

  
......
2872 2873
    }
2873 2874
    cell.save()
2874 2875
    result = cell.render(context)
2876
    assert len(PyQuery(result).find('.cell--body > div > div')) == 1
2875 2877
    assert PyQuery(result).find('.label').text() == 'Empty'
2876 2878
    assert PyQuery(result).find('.value').text() == ''
2877 2879

  
......
2883 2885
    }
2884 2886
    cell.save()
2885 2887
    result = cell.render(context)
2888
    assert len(PyQuery(result).find('.cell--body > div > div')) == 1
2886 2889
    assert PyQuery(result).find('.label').text() == 'Empty'
2887 2890
    assert PyQuery(result).find('.value').text() == 'Custom text'
2888 2891

  
......
2904 2907
            }
2905 2908
            cell.save()
2906 2909
            result = cell.render(context)
2910
            assert len(PyQuery(result).find('.cell--body > div > div')) == 0
2907 2911
            assert PyQuery(result).find(html_tag) == []
2908 2912

  
2909 2913
            cell.custom_schema['cells'][0] = {
......
2914 2918
            }
2915 2919
            cell.save()
2916 2920
            result = cell.render(context)
2921
            assert len(PyQuery(result).find('.cell--body > div > div')) == 1
2917 2922
            assert PyQuery(result).find(html_tag).text() == ('Empty' if field_content == 'label' else '')
2918 2923

  
2919 2924
            cell.custom_schema['cells'][0] = {
......
2924 2929
            }
2925 2930
            cell.save()
2926 2931
            result = cell.render(context)
2932
            assert len(PyQuery(result).find('.cell--body > div > div')) == 1
2927 2933
            assert PyQuery(result).find(html_tag).text() == (
2928 2934
                'Empty' if field_content == 'label' else 'Custom text'
2929 2935
            )
2930
-