Projet

Général

Profil

0001-misc-remove-duplicated-code-67254.patch

Lauréline Guérin, 15 juillet 2022 17:03

Télécharger (2,42 ko)

Voir les différences:

Subject: [PATCH] misc: remove duplicated code (#67254)

 combo/public/views.py | 10 ----------
 tests/test_public.py  |  9 +++++++--
 2 files changed, 7 insertions(+), 12 deletions(-)
combo/public/views.py
345 345
    extend_with_parent_cells(cells, hierarchy=pages)
346 346
    mark_duplicated_slugs(cells)
347 347

  
348
    # mark duplicated slugs to avoid using them in HTML id attributes.
349
    cell_by_slugs = {}
350
    for cell in cells:
351
        if cell.slug not in cell_by_slugs:
352
            cell_by_slugs[cell.slug] = []
353
        cell_by_slugs[cell.slug].append(cell)
354
    for slug_cells in cell_by_slugs.values():
355
        for cell in slug_cells:
356
            cell.use_slug_as_id = bool(len(slug_cells) == 1)
357

  
358 348
    ctx = {
359 349
        'page': selected_page,
360 350
        'page_cells': cells,
tests/test_public.py
356 356
    resp = app.get('/__skeleton__/?source=%s' % quote('http://example.com/foo/bar'), status=403)
357 357

  
358 358
    # check with a footer cell
359
    cell = TextCell(page=page, placeholder='footer', text='Foobar', order=0)
360
    cell.save()
359
    TextCell.objects.create(page=page, placeholder='footer', text='Foobar', order=0)
360
    TextCell.objects.create(page=page, placeholder='content', text='Foobar', slug='unique', order=1)
361
    TextCell.objects.create(page=page, placeholder='content', text='Foobar', slug='dup', order=2)
362
    TextCell.objects.create(page=page, placeholder='content', text='Foobar', slug='dup', order=3)
361 363
    resp = app.get('/__skeleton__/?source=%s' % quote('http://example.net'))
362 364
    assert '{% block placeholder-content %}{% block content %}{% endblock %}{% endblock %}' in resp.text
363 365
    assert '{% block placeholder-footer %}{% block footer %}{% endblock %}{% endblock %}' in resp.text
364 366
    assert 'Foobar' in resp.text
367
    # check slugs
368
    assert 'id="unique"' in resp.text
369
    assert 'id="dup"' not in resp.text
365 370

  
366 371
    # check {% now %} inside a skeleton_extra_placeholder is not interpreted
367 372
    assert '{% now ' in resp.text
368
-