0001-misc-add-BEM-classes-on-link-list-cell-70837.patch
combo/apps/wcs/templates/combo/wcs/form_link_fragment.html | ||
---|---|---|
6 | 6 | |
7 | 7 | |
8 | 8 |
{% block form-link-pre %}{% endblock %} |
9 |
<a href="{{ form_url }}{% if not request_is_a_bot %}tryauth?cancelurl={{ absolute_uri|urlencode|iriencode }}{% endif %}">{% block form-link-title %}{{ form_title }}{% endblock %}</a> |
|
9 |
<a |
|
10 |
{% if css_block %} |
|
11 |
class="{{css_block}}--link" |
|
12 |
{% endif %} |
|
13 |
href="{{ form_url }}{% if not request_is_a_bot %}tryauth?cancelurl={{ absolute_uri|urlencode|iriencode }}{% endif %}"> |
|
14 |
{% block form-link-title %}{{ form_title }}{% endblock %} |
|
15 |
</a> |
|
10 | 16 |
{% if form_description %} |
11 | 17 |
<div class="description">{% block form-link-description %}{{ form_description|safe }}{% endblock %}</div> |
12 | 18 |
{% endif %} |
combo/public/templates/combo/link-list-cell.html | ||
---|---|---|
2 | 2 |
{% block cell-content %} |
3 | 3 |
{% spaceless %} |
4 | 4 |
{% block cell-header %} |
5 |
{% if title %}<h2>{{ title }}</h2>{% endif %} |
|
5 |
{% if title %}<h2 class="cell--title">{{ title }}</h2>{% endif %}
|
|
6 | 6 |
{% include "combo/asset_picture_fragment.html" %} |
7 | 7 |
{% endblock cell-header %} |
8 | 8 |
<div class="links-list"> |
9 | 9 |
{% block cell-top-content %}{% endblock cell-top-content %} |
10 |
<ul> |
|
10 |
<ul class="links-list--items">
|
|
11 | 11 |
{% for link in links %} |
12 |
<li class="{{ link.css_classes|default:""|join:" " }}{% if link.cell.extra_css_class %} {{ link.cell.extra_css_class }}{% endif %}">{% if link.is_form %} |
|
13 |
{% include "combo/wcs/form_link_fragment.html" with form=link %} |
|
12 |
<li class="links-list--item {{ link.css_classes|default:""|join:" " }}{% if link.cell.extra_css_class %} {{ link.cell.extra_css_class }}{% endif %}">{% if link.is_form %}
|
|
13 |
{% include "combo/wcs/form_link_fragment.html" with form=link css_block="links-list" %}
|
|
14 | 14 |
{% else %} |
15 |
<a href="{{ link.url }}">{{ link.title }}</a> |
|
15 |
<a href="{{ link.url }}" class="links-list--link">{{ link.title }}</a>
|
|
16 | 16 |
{% endif %}</li> |
17 | 17 |
{% endfor %} |
18 | 18 |
{% if more_links %} |
19 |
<li class="add-more-items"> |
|
20 |
<a role="button" tabindex="0" aria-expanded="false" aria-controls="more-items-{{ cell.get_reference }}" aria-label="{% trans 'More items' %}" id="btn-more-items-{{ cell.get_reference }}" class="add-more-items--button">{% block cell-more-items-btn-label %}+{% endblock %}</a> |
|
19 |
<li class="add-more-items links-list--more-item">
|
|
20 |
<a role="button" tabindex="0" aria-expanded="false" aria-controls="more-items-{{ cell.get_reference }}" aria-label="{% trans 'More items' %}" id="btn-more-items-{{ cell.get_reference }}" class="add-more-items--button links-list--more-button">{% block cell-more-items-btn-label %}+{% endblock %}</a>
|
|
21 | 21 |
</li> |
22 | 22 |
{% endif %} |
23 | 23 |
</ul> |
24 | 24 | |
25 | 25 |
{% if more_links %} |
26 |
<ul style="display: none" class="more-items" id="more-items-{{ cell.get_reference }}" aria-labelledby="btn-more-items-{{ cell.get_reference }}"> |
|
26 |
<ul style="display: none" class="more-items links-list--items" id="more-items-{{ cell.get_reference }}" aria-labelledby="btn-more-items-{{ cell.get_reference }}">
|
|
27 | 27 |
{% for link in more_links %} |
28 |
<li class="more-items--item {{ link.css_classes|default:""|join:" " }}">{% if link.is_form %} |
|
29 |
{% include "combo/wcs/form_link_fragment.html" with form=link %} |
|
28 |
<li class="more-items--item links-list--item {{ link.css_classes|default:""|join:" " }}">{% if link.is_form %}
|
|
29 |
{% include "combo/wcs/form_link_fragment.html" with form=link css_block="links-list"%}
|
|
30 | 30 |
{% else %} |
31 |
<a href="{{ link.url }}">{{ link.title }}</a> |
|
31 |
<a class="links-list--link" href="{{ link.url }}">{{ link.title }}</a>
|
|
32 | 32 |
{% endif %}</li> |
33 | 33 |
{% endfor %} |
34 | 34 |
{% endif %} |
tests/test_cells.py | ||
---|---|---|
19 | 19 |
from django.urls import reverse |
20 | 20 |
from django.utils.encoding import force_bytes, force_str |
21 | 21 |
from django.utils.timezone import now |
22 |
from pyquery import PyQuery |
|
22 | 23 | |
23 | 24 |
from combo.data.library import get_cell_classes |
24 | 25 |
from combo.data.models import ( |
... | ... | |
291 | 292 |
) |
292 | 293 | |
293 | 294 |
ctx = {'page_cells': [item]} |
294 |
assert '<ul><li class=" foobar"><a href="http://example.net/">Example Site</a></li></ul>' in cell.render( |
|
295 |
ctx |
|
296 |
) |
|
295 |
p = PyQuery(cell.render(ctx)) |
|
296 |
assert p("a").attr("href") == "http://example.net/" |
|
297 |
assert p("a").text() == "Example Site" |
|
298 |
assert "foobar" in p("li").attr("class") |
|
297 | 299 | |
298 | 300 |
item.title = '' |
299 | 301 |
item.extra_css_class = '' |
300 |
assert '<ul><li class=""><a href="http://example.net/">http://example.net/</a></li></ul>' in cell.render(
|
|
301 |
ctx
|
|
302 |
) |
|
302 |
p = PyQuery(cell.render(ctx))
|
|
303 |
assert p("a").text() == "http://example.net/"
|
|
304 |
assert "foobar" not in p("li").attr("class")
|
|
303 | 305 | |
304 | 306 |
item.link_page = page |
305 |
assert '<ul><li class=""><a href="/example-page/">example page</a></li></ul>' in cell.render(ctx) |
|
307 |
p = PyQuery(cell.render(ctx))("a") |
|
308 |
assert p.attr("href") == "/example-page/" |
|
309 |
assert p.text() == "example page" |
|
306 | 310 | |
307 | 311 |
item.title = 'altertitle' |
308 |
assert '<ul><li class=""><a href="/example-page/">altertitle</a></li></ul>' in cell.render(ctx) |
|
312 |
p = PyQuery(cell.render(ctx))("a") |
|
313 |
assert p.text() == "altertitle" |
|
309 | 314 | |
310 | 315 |
item.anchor = 'anchor' |
311 |
assert '<ul><li class=""><a href="/example-page/#anchor">altertitle</a></li></ul>' in cell.render(ctx) |
|
316 |
p = PyQuery(cell.render(ctx))("a") |
|
317 |
assert p.attr("href") == "/example-page/#anchor" |
|
312 | 318 | |
313 | 319 |
item.link_page = None |
314 |
assert '<ul><li class=""><a href="http://example.net/#anchor">altertitle</a></li></ul>' in cell.render( |
|
315 |
ctx |
|
316 |
) |
|
320 |
p = PyQuery(cell.render(ctx))("a") |
|
321 |
assert p.attr("href") == "http://example.net/#anchor" |
|
317 | 322 | |
318 | 323 |
item2 = LinkCell.objects.create( |
319 | 324 |
page=page, |
... | ... | |
323 | 328 |
order=1, |
324 | 329 |
) |
325 | 330 |
ctx = {'page_cells': [item, item2]} |
326 |
assert 'class="add-more-items--button">+</a>' not in cell.render(ctx) |
|
331 |
assert 'class="add-more-items--button links-list--more-button">+</a>' not in cell.render(ctx)
|
|
327 | 332 |
cell.limit = 1 |
328 |
assert 'class="add-more-items--button">+</a>' in cell.render(ctx) |
|
333 |
assert 'class="add-more-items--button links-list--more-button">+</a>' in cell.render(ctx)
|
|
329 | 334 | |
330 | 335 | |
331 | 336 |
def test_link_list_cell_validity(): |
tests/wcs/test_all.py | ||
---|---|---|
1860 | 1860 | |
1861 | 1861 |
resp = app.get('/test_list_of_links_with_form_render/') |
1862 | 1862 |
assert PyQuery(resp.text).find('.links-list a').text() == 'A title' |
1863 |
assert PyQuery(resp.text).find('.links-list li').attr('class') == ' foobar'
|
|
1863 |
assert 'foobar' in PyQuery(resp.text).find('.links-list li').attr('class')
|
|
1864 | 1864 |
assert ( |
1865 | 1865 |
PyQuery(resp.text).find('.links-list a').attr('href') |
1866 | 1866 |
== 'http://example.com/tryauth?cancelurl=http%3A//testserver/test_list_of_links_with_form_render/' |
... | ... | |
1869 | 1869 |
link.cached_json = {'keywords': ['bar']} |
1870 | 1870 |
link.save() |
1871 | 1871 |
resp = app.get('/test_list_of_links_with_form_render/') |
1872 |
assert PyQuery(resp.text).find('.links-list li').attr('class') == 'keyword-bar foobar'
|
|
1872 |
assert 'keyword-bar foobar' in PyQuery(resp.text).find('.links-list li').attr('class')
|
|
1873 | 1873 | |
1874 | 1874 |
link.extra_css_class = '' |
1875 | 1875 |
link.save() |
1876 | 1876 |
resp = app.get('/test_list_of_links_with_form_render/') |
1877 |
assert PyQuery(resp.text).find('.links-list li').attr('class') == 'keyword-bar'
|
|
1877 |
assert 'keyword-bar' in PyQuery(resp.text).find('.links-list li').attr('class')
|
|
1878 | 1878 | |
1879 | 1879 | |
1880 | 1880 |
def test_view_page_with_wcs_cells_num_queries(app, admin_user): |
1881 |
- |