misc: use unique cell slug as id on skeleton pages (#35087)
This commit is contained in:
parent
32663dc98e
commit
ce2210a108
|
@ -188,6 +188,18 @@ def should_check_badges():
|
||||||
return 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):
|
def skeleton(request):
|
||||||
# Skeleton rendering is used to dynamically produce base templates to use
|
# Skeleton rendering is used to dynamically produce base templates to use
|
||||||
# in other applications, based on configured combo cells.
|
# in other applications, based on configured combo cells.
|
||||||
|
@ -280,6 +292,17 @@ def skeleton(request):
|
||||||
pages = selected_page.get_parents_and_self()
|
pages = selected_page.get_parents_and_self()
|
||||||
combo_template = settings.COMBO_PUBLIC_TEMPLATES[selected_page.template_name]
|
combo_template = settings.COMBO_PUBLIC_TEMPLATES[selected_page.template_name]
|
||||||
extend_with_parent_cells(cells, hierarchy=pages)
|
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 = {
|
ctx = {
|
||||||
'page': selected_page,
|
'page': selected_page,
|
||||||
|
@ -460,16 +483,7 @@ def publish_page(request, page, status=200, template_name=None):
|
||||||
cells = CellBase.get_cells(page=page)
|
cells = CellBase.get_cells(page=page)
|
||||||
extend_with_parent_cells(cells, hierarchy=pages)
|
extend_with_parent_cells(cells, hierarchy=pages)
|
||||||
cells = [x for x in cells if x.is_visible(user=request.user)]
|
cells = [x for x in cells if x.is_visible(user=request.user)]
|
||||||
|
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 = {
|
ctx = {
|
||||||
'check_badges': should_check_badges(),
|
'check_badges': should_check_badges(),
|
||||||
|
|
Loading…
Reference in New Issue