Projet

Général

Profil

0001-misc-use-unique-cell-slug-as-id-on-skeleton-pages-35.patch

Frédéric Péters, 27 juillet 2019 18:03

Télécharger (2,63 ko)

Voir les différences:

Subject: [PATCH] misc: use unique cell slug as id on skeleton pages (#35087)

 combo/public/views.py | 34 ++++++++++++++++++++++++----------
 1 file changed, 24 insertions(+), 10 deletions(-)
combo/public/views.py
188 188
    return check_badges
189 189

  
190 190

  
191
def mark_duplicated_slugs(cells):
192
    # mark duplicated slugs to avoid using them in HTML id attributes.
193
    cell_by_slugs = {}
194
    for cell in cells:
195
        if cell.slug not in cell_by_slugs:
196
            cell_by_slugs[cell.slug] = []
197
        cell_by_slugs[cell.slug].append(cell)
198
    for slug, slug_cells in cell_by_slugs.items():
199
        for cell in slug_cells:
200
            cell.use_slug_as_id = bool(len(slug_cells) == 1)
201

  
202

  
191 203
def skeleton(request):
192 204
    # Skeleton rendering is used to dynamically produce base templates to use
193 205
    # in other applications, based on configured combo cells.
......
280 292
    pages = selected_page.get_parents_and_self()
281 293
    combo_template = settings.COMBO_PUBLIC_TEMPLATES[selected_page.template_name]
282 294
    extend_with_parent_cells(cells, hierarchy=pages)
295
    mark_duplicated_slugs(cells)
296

  
297
    # mark duplicated slugs to avoid using them in HTML id attributes.
298
    cell_by_slugs = {}
299
    for cell in cells:
300
        if cell.slug not in cell_by_slugs:
301
            cell_by_slugs[cell.slug] = []
302
        cell_by_slugs[cell.slug].append(cell)
303
    for slug, slug_cells in cell_by_slugs.items():
304
        for cell in slug_cells:
305
            cell.use_slug_as_id = bool(len(slug_cells) == 1)
283 306

  
284 307
    ctx = {
285 308
        'page': selected_page,
......
463 486
    cells = CellBase.get_cells(page=page)
464 487
    extend_with_parent_cells(cells, hierarchy=pages)
465 488
    cells = [x for x in cells if x.is_visible(user=request.user)]
466

  
467
    # mark duplicated slugs to avoid using them in HTML id attributes.
468
    cell_by_slugs = {}
469
    for cell in cells:
470
        if cell.slug not in cell_by_slugs:
471
            cell_by_slugs[cell.slug] = []
472
        cell_by_slugs[cell.slug].append(cell)
473
    for slug, slug_cells in cell_by_slugs.items():
474
        for cell in slug_cells:
475
            cell.use_slug_as_id = bool(len(slug_cells) == 1)
489
    mark_duplicated_slugs(cells)
476 490

  
477 491
    ctx = {
478 492
        'check_badges': should_check_badges(),
479
-