From c81c303e0ac3c087f0d5fd7a628f9b6eaa5eccf0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Fri, 2 Sep 2022 19:28:10 +0200 Subject: [PATCH] misc: inherit placeholder options when using parent content cells (#68679) --- combo/data/models.py | 12 +++++++++++- combo/public/views.py | 2 +- tests/test_public.py | 21 +++++++++++++++++++++ 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/combo/data/models.py b/combo/data/models.py index 70488db1..91f5a93e 100644 --- a/combo/data/models.py +++ b/combo/data/models.py @@ -1987,7 +1987,7 @@ class ParentContentCell(CellBase): class Meta: verbose_name = _('Same as parent') - def get_parents_cells(self, hierarchy): + def get_parents_cells(self, hierarchy, leaf): try: pages = [Page.objects.get(slug='index', parent=None)] except Page.DoesNotExist: @@ -2010,6 +2010,16 @@ class ParentContentCell(CellBase): cells_by_page[cell.page_id].append(cell) cells = cells_by_page[pages[-1].id] + if not leaf.placeholder_options.get(self.placeholder): + for page in reversed(pages): + # if there's no placeholder options then we copy placeholder + # options from parent page. + if page.placeholder_options.get(self.placeholder): + leaf.placeholder_options[cell.placeholder] = page.placeholder_options.get( + self.placeholder + ) + break + for page in reversed(pages[:-1]): for i, cell in enumerate(cells): if isinstance(cell, ParentContentCell): diff --git a/combo/public/views.py b/combo/public/views.py index 691d134f..cb02f896 100644 --- a/combo/public/views.py +++ b/combo/public/views.py @@ -211,7 +211,7 @@ def extend_with_parent_cells(cells, hierarchy): if not isinstance(cell, ParentContentCell): continue idx = cells.index(cell) - parent_cells = cell.get_parents_cells(hierarchy=hierarchy[:-1]) + parent_cells = cell.get_parents_cells(hierarchy=hierarchy[:-1], leaf=hierarchy[-1]) # keep cells that were not already seen and mark cells as seen, # simultaneously. parent_cells = [ diff --git a/tests/test_public.py b/tests/test_public.py index f98d17f2..02b20ce7 100644 --- a/tests/test_public.py +++ b/tests/test_public.py @@ -249,6 +249,27 @@ def test_page_footer_acquisition(app): assert resp.text.count('BARFOO') == 1 +def test_page_footer_grid_acquisition(app): + Page.objects.all().delete() + index_page = Page(title='Home', slug='index', template_name='standard') + index_page.placeholder_options = {'footer': {'fx_grid_layout': 'fx-grid'}} + index_page.save() + cell = TextCell(page=index_page, placeholder='footer', text='BARFOO', order=0) + cell.save() + + page2 = Page(title='Second', slug='second', template_name='standard') + page2.save() + ParentContentCell(page=page2, placeholder='footer', order=0).save() + + page3 = Page(title='Third', slug='third', template_name='standard') + page3.save() + ParentContentCell(page=page3, placeholder='footer', order=0).save() + + # check placeholder options are inherited + resp = app.get(page3.get_online_url()) + assert resp.pyquery('#footer > .fx-grid > .text-cell') + + def test_list_of_links_acquisition(app): Page.objects.all().delete() index_page = Page(title='Home', slug='index', template_name='standard')