diff --git a/combo/public/views.py b/combo/public/views.py index f37b3c6b..435dff6c 100644 --- a/combo/public/views.py +++ b/combo/public/views.py @@ -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(),