misc: use unique cell slug as id on skeleton pages (#35087)

This commit is contained in:
Frédéric Péters 2019-07-27 17:57:58 +02:00 committed by Thomas NOEL
parent 4167cf082a
commit 226404bbbc
1 changed files with 24 additions and 10 deletions

View File

@ -188,6 +188,18 @@ def should_check_badges():
return check_badges
def 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, slug_cells in cell_by_slugs.items():
for cell in slug_cells:
cell.use_slug_as_id = bool(len(slug_cells) == 1)
def skeleton(request):
# Skeleton rendering is used to dynamically produce base templates to use
# in other applications, based on configured combo cells.
@ -280,6 +292,17 @@ def skeleton(request):
pages = selected_page.get_parents_and_self()
combo_template = settings.COMBO_PUBLIC_TEMPLATES[selected_page.template_name]
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, slug_cells in cell_by_slugs.items():
for cell in slug_cells:
cell.use_slug_as_id = bool(len(slug_cells) == 1)
ctx = {
'page': selected_page,
@ -460,16 +483,7 @@ def publish_page(request, page, status=200, template_name=None):
cells = CellBase.get_cells(page=page)
extend_with_parent_cells(cells, hierarchy=pages)
cells = [x for x in cells if x.is_visible(user=request.user)]
# 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, slug_cells in cell_by_slugs.items():
for cell in slug_cells:
cell.use_slug_as_id = bool(len(slug_cells) == 1)
mark_duplicated_slugs(cells)
ctx = {
'check_badges': should_check_badges(),