misc: remove duplicated code (#67254)
gitea-wip/combo/pipeline/head There was a failure building this commit Details
gitea/combo/pipeline/head Something is wrong with the build of this commit Details

This commit is contained in:
Lauréline Guérin 2022-07-15 16:58:35 +02:00
parent 4ed8ebcf21
commit c240f32a66
No known key found for this signature in database
GPG Key ID: 1FAB9B9B4F93D473
2 changed files with 7 additions and 12 deletions

View File

@ -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,

View File

@ -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