diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 119f92f7f1..388c739755 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -31,6 +31,7 @@ Changelog * Fix: Users with only publish permission are no longer given implicit permission to delete pages (Matt Westcott) * Fix: `search_garbage_collect` management command now works when wagtailsearchpromotions is not installed (Morgan Aubert) * Fix: `wagtail.contrib.settings` context processor no longer fails when `request.site` is unavailable (Diederik van der Boor) + * Fix: `TableBlock` content is now indexed for search (Morgan Aubert) 1.7 (20.10.2016) diff --git a/docs/releases/1.8.rst b/docs/releases/1.8.rst index e586704d52..81b1ae74eb 100644 --- a/docs/releases/1.8.rst +++ b/docs/releases/1.8.rst @@ -62,6 +62,8 @@ Bug fixes * Users with only publish permission are no longer given implicit permission to delete pages (Matt Westcott) * ``search_garbage_collect`` management command now works when wagtailsearchpromotions is not installed (Morgan Aubert) * ``wagtail.contrib.settings`` context processor no longer fails when ``request.site`` is unavailable (Diederik van der Boor) + * ``TableBlock`` content is now indexed for search (Morgan Aubert) + Upgrade considerations ====================== diff --git a/wagtail/contrib/table_block/blocks.py b/wagtail/contrib/table_block/blocks.py index f4272b7e77..22acfdf052 100644 --- a/wagtail/contrib/table_block/blocks.py +++ b/wagtail/contrib/table_block/blocks.py @@ -74,6 +74,12 @@ class TableBlock(FieldBlock): def is_html_renderer(self): return self.table_options['renderer'] == 'html' + def get_searchable_content(self, value): + content = [] + for row in value.get('data', []): + content.extend([v for v in row if v]) + return content + def render(self, value, context=None): template = getattr(self.meta, 'template', None) if template and value: diff --git a/wagtail/contrib/table_block/tests.py b/wagtail/contrib/table_block/tests.py index 6662aebe2d..01985e52dc 100644 --- a/wagtail/contrib/table_block/tests.py +++ b/wagtail/contrib/table_block/tests.py @@ -172,6 +172,14 @@ class TestTableBlock(TestTableBlockRenderingBase): block2 = TableBlock(table_options=new_options) self.assertEqual(block2.is_html_renderer(), True) + def test_searchable_content(self): + value = {'first_row_is_table_header': False, 'first_col_is_header': False, + 'data': [['Test 1', 'Test 2', 'Test 3'], [None, 'Bar', None], + [None, 'Foo', None]]} + block = TableBlock() + content = block.get_searchable_content(value) + self.assertEqual(content, ['Test 1', 'Test 2', 'Test 3', 'Bar', 'Foo', ]) + def test_render_with_extra_context(self): """ Test that extra context variables passed in block.render are passed through