From c240f32a669c1dd16c1feb47cbc2d0df3b007159 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Laur=C3=A9line=20Gu=C3=A9rin?= Date: Fri, 15 Jul 2022 16:58:35 +0200 Subject: [PATCH] misc: remove duplicated code (#67254) --- combo/public/views.py | 10 ---------- tests/test_public.py | 9 +++++++-- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/combo/public/views.py b/combo/public/views.py index 5b853d81..ec09a894 100644 --- a/combo/public/views.py +++ b/combo/public/views.py @@ -345,16 +345,6 @@ def skeleton(request): extend_with_parent_cells(cells, hierarchy=pages) mark_duplicated_slugs(cells) - # mark duplicated slugs to avoid using them in HTML id attributes. - cell_by_slugs = {} - for cell in cells: - if cell.slug not in cell_by_slugs: - cell_by_slugs[cell.slug] = [] - cell_by_slugs[cell.slug].append(cell) - for slug_cells in cell_by_slugs.values(): - for cell in slug_cells: - cell.use_slug_as_id = bool(len(slug_cells) == 1) - ctx = { 'page': selected_page, 'page_cells': cells, diff --git a/tests/test_public.py b/tests/test_public.py index e07a4d81..28d222bc 100644 --- a/tests/test_public.py +++ b/tests/test_public.py @@ -356,12 +356,17 @@ def test_page_skeleton(app): resp = app.get('/__skeleton__/?source=%s' % quote('http://example.com/foo/bar'), status=403) # check with a footer cell - cell = TextCell(page=page, placeholder='footer', text='Foobar', order=0) - cell.save() + TextCell.objects.create(page=page, placeholder='footer', text='Foobar', order=0) + TextCell.objects.create(page=page, placeholder='content', text='Foobar', slug='unique', order=1) + TextCell.objects.create(page=page, placeholder='content', text='Foobar', slug='dup', order=2) + TextCell.objects.create(page=page, placeholder='content', text='Foobar', slug='dup', order=3) resp = app.get('/__skeleton__/?source=%s' % quote('http://example.net')) assert '{% block placeholder-content %}{% block content %}{% endblock %}{% endblock %}' in resp.text assert '{% block placeholder-footer %}{% block footer %}{% endblock %}{% endblock %}' in resp.text assert 'Foobar' in resp.text + # check slugs + assert 'id="unique"' in resp.text + assert 'id="dup"' not in resp.text # check {% now %} inside a skeleton_extra_placeholder is not interpreted assert '{% now ' in resp.text