Projet

Général

Profil

0004-wcs-do-not-show-A-anchor-if-URL-and-label-are-empty-.patch

Lauréline Guérin, 30 août 2022 16:44

Télécharger (3,85 ko)

Voir les différences:

Subject: [PATCH 4/4] wcs: do not show A anchor if URL and label are empty
 (#62137)

 combo/apps/wcs/templates/combo/wcs/card.html |  8 ++++---
 tests/wcs/test_card.py                       | 24 ++++++++++++++++++++
 2 files changed, 29 insertions(+), 3 deletions(-)
combo/apps/wcs/templates/combo/wcs/card.html
34 34
          {% endif %}
35 35
        {% elif item.varname == "@link@" %}
36 36
          {% if item.template and item.page|default:item.url_template %}
37
          <div class="{{ item.cell_size|default:"" }}">
38 37
            {% with item.page|default:item.url_template as url_key %}
39 38
            {% with card.custom_fields|get:item.template|force_escape as link_label and card.urls|get:url_key|force_escape as link_url %}
40
            <div class="value"><a href="{{ link_url }}"{% if item.display_mode == 'button' %} class="pk-button"{% endif %}>{{ link_label }}</a></div>
39
            {% if link_label and link_url %}
40
              <div class="{{ item.cell_size|default:"" }}">
41
                <div class="value"><a href="{{ link_url }}"{% if item.display_mode == 'button' %} class="pk-button"{% endif %}>{{ link_label }}</a></div>
42
              </div>
43
            {% endif %}
41 44
            {% endwith %}
42 45
            {% endwith %}
43
          </div>
44 46
          {% endif %}
45 47
        {% else %}
46 48
          {% with fields_by_varnames|get:item.varname as field %}
tests/wcs/test_card.py
1571 1571
        in cell_resp
1572 1572
    )
1573 1573

  
1574
    # empty label or empty url: no link in output
1575
    cell.custom_schema['cells'][0]['url_template'] = '{{ None|default:"" }}'
1576
    cell.save()
1577
    result = cell.render(context)
1578
    assert PyQuery(result).find('.value a') == []
1579
    cell.custom_schema['cells'][0]['url_template'] = 'foo/bar'
1580
    cell.custom_schema['cells'][0]['template'] = '{{ None|default:"" }}'
1581
    cell.save()
1582
    result = cell.render(context)
1583
    assert PyQuery(result).find('.value a') == []
1584

  
1574 1585
    # check with page link
1575 1586
    root_page = Page.objects.create(title='Root', slug='root', template_name='standard')
1576 1587
    page1 = Page.objects.create(
......
1589 1600
        parent=other_root_page,
1590 1601
    )
1591 1602

  
1603
    cell.custom_schema['cells'][0]['url_template'] = ''
1592 1604
    cell.custom_schema['cells'][0]['page'] = page1.pk
1605
    cell.custom_schema['cells'][0]['template'] = 'Foo'
1593 1606
    cell.save()
1594 1607
    result = cell.render(context)
1595 1608
    assert PyQuery(result).find('.value a').attr['href'] == '/root/card/11/'
......
1599 1612
    result = cell.render(context)
1600 1613
    assert PyQuery(result).find('.value a').attr['href'] == '/other-root/card-bis/11/'
1601 1614

  
1615
    # empty label or empty url: no link in output
1616
    cell.custom_schema['cells'][0]['page'] = 0
1617
    cell.save()
1618
    result = cell.render(context)
1619
    assert PyQuery(result).find('.value a') == []
1620
    cell.custom_schema['cells'][0]['page'] = page1.pk
1621
    cell.custom_schema['cells'][0]['template'] = '{{ None|default:"" }}'
1622
    cell.save()
1623
    result = cell.render(context)
1624
    assert PyQuery(result).find('.value a') == []
1625

  
1602 1626

  
1603 1627
@mock.patch('requests.Session.send', side_effect=mocked_requests_send)
1604 1628
def test_card_cell_card_mode_render_all_cards(mock_send, nocache, app):
1605
-