Skip to content

Commit ca1d711

Browse files
committed
auto_rowspan on a generator gives an empty table
1 parent 46b2b53 commit ca1d711

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

iommi/table.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2220,7 +2220,8 @@ def on_bind(self) -> None:
22202220
bind_member(self, name='bulk_container')
22212221

22222222
def get_visible_rows(self):
2223-
self.visible_rows = self.parts.page.rows
2223+
if self.visible_rows is None:
2224+
self.visible_rows = list(self.parts.page.rows)
22242225
return self.visible_rows
22252226

22262227
def _bind_query(self):
@@ -2280,7 +2281,6 @@ def render_actions(self):
22802281
def _prepare_auto_rowspan(self):
22812282
auto_rowspan_columns = [column for column in values(self.columns) if column.auto_rowspan]
22822283
if auto_rowspan_columns:
2283-
self.visible_rows = list(self.get_visible_rows())
22842284
no_value_set = object()
22852285
for column in auto_rowspan_columns:
22862286
if column.cell.attrs.get('rowspan', no_value_set) is not no_value_set:

iommi/table__tests.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4468,3 +4468,34 @@ def test_annotate_on_broken_filters():
44684468
</tbody>
44694469
""",
44704470
)
4471+
4472+
4473+
def test_auto_rowspan_and_render_twice_generator(NoSortTable): # noqa: N803
4474+
class TestTable(NoSortTable):
4475+
foo = Column(auto_rowspan=True)
4476+
4477+
rows = [
4478+
Struct(foo=1),
4479+
Struct(foo=1),
4480+
Struct(foo=2),
4481+
Struct(foo=2),
4482+
]
4483+
4484+
# language=html
4485+
expected_html = """
4486+
<table class="table" >
4487+
<thead>
4488+
<tr> <th class="first_column subheader"> Foo </th> </tr>
4489+
</thead>
4490+
<tbody>
4491+
<tr> <td rowspan="2"> 1 </td> </tr>
4492+
<tr> <td style="display: none"> 1 </td> </tr>
4493+
<tr> <td rowspan="2"> 2 </td> </tr>
4494+
<tr> <td style="display: none"> 2 </td> </tr>
4495+
</tbody>
4496+
</table>"""
4497+
4498+
t = TestTable(rows=(x for x in rows))
4499+
t = t.bind(request=req('get'))
4500+
verify_table_html(table=t, expected_html=expected_html)
4501+
verify_table_html(table=t, expected_html=expected_html)

0 commit comments

Comments
 (0)