general: make sure footer elements from homepage are not duplicated (#22058)
This commit is contained in:
parent
3becfdcc87
commit
cb0b80f9bb
|
@ -843,6 +843,9 @@ class ParentContentCell(CellBase):
|
|||
page_ids.extend([x.id for x in hierarchy])
|
||||
if not page_ids:
|
||||
return []
|
||||
if len(page_ids) > 1 and page_ids[0] == page_ids[1]:
|
||||
# don't duplicate index cells for real children of the index page.
|
||||
page_ids = page_ids[1:]
|
||||
cells_by_page = {}
|
||||
for page_id in page_ids:
|
||||
cells_by_page[page_id] = []
|
||||
|
|
|
@ -129,6 +129,9 @@ def render_cell(request, cell):
|
|||
|
||||
|
||||
def extend_with_parent_cells(cells, hierarchy):
|
||||
if len(hierarchy) == 1 and hierarchy[0].slug == 'index':
|
||||
# home page cannot contain parent cells
|
||||
return
|
||||
for cell in cells[:]:
|
||||
if not isinstance(cell, ParentContentCell):
|
||||
continue
|
||||
|
|
|
@ -66,11 +66,18 @@ def test_page_footer_acquisition(app):
|
|||
Page.objects.all().delete()
|
||||
page = Page(title='Home', slug='index', template_name='standard')
|
||||
page.save()
|
||||
page_index = page
|
||||
cell = TextCell(page=page, placeholder='footer', text='BARFOO', order=0)
|
||||
cell.save()
|
||||
resp = app.get('/', status=200)
|
||||
assert resp.body.count('BARFOO') == 1
|
||||
|
||||
# make sure a parent content cell in the home page doesn't duplicate
|
||||
# cells
|
||||
ParentContentCell(page=page, placeholder='footer', order=0).save()
|
||||
resp = app.get('/', status=200)
|
||||
assert resp.body.count('BARFOO') == 1
|
||||
|
||||
page = Page(title='Second', slug='second', template_name='standard')
|
||||
page.save()
|
||||
ParentContentCell(page=page, placeholder='footer', order=0).save()
|
||||
|
@ -111,6 +118,14 @@ def test_page_footer_acquisition(app):
|
|||
queries_count_fourth = len(ctx.captured_queries)
|
||||
assert queries_count_fourth == queries_count_second + 2
|
||||
|
||||
# check footer doesn't get duplicated in real index children
|
||||
page6 = Page(title='Sixth', slug='sixth', template_name='standard', parent=page_index)
|
||||
page6.save()
|
||||
ParentContentCell(page=page6, placeholder='footer', order=0).save()
|
||||
|
||||
resp = app.get('/sixth/', status=200)
|
||||
assert resp.body.count('BARFOO') == 1
|
||||
|
||||
def test_page_redirect(app):
|
||||
Page.objects.all().delete()
|
||||
page = Page(title='Elsewhere', slug='elsewhere', template_name='standard',
|
||||
|
|
Loading…
Reference in New Issue