Fix #3167 - Ensure TableBlock content is indexed

Changes include:
* adding the 'get_searchable_content' method on the TableBlock
* ... and the related test
pull/3071/merge
Morgan Aubert 2016-11-25 16:17:20 -05:00 zatwierdzone przez Matt Westcott
rodzic 3d37f84311
commit 4e23e46159
4 zmienionych plików z 17 dodań i 0 usunięć

Wyświetl plik

@ -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)

Wyświetl plik

@ -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
======================

Wyświetl plik

@ -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:

Wyświetl plik

@ -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