Skip to content

Commit bf42778

Browse files
author
Steve Canny
committed
tbl: base Table on Parented
1 parent 5908c85 commit bf42778

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

docx/parts/document.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ def add_table(self, rows, cols):
135135
the main document story.
136136
"""
137137
tbl = self._body.add_tbl()
138-
table = Table(tbl)
138+
table = Table(tbl, self)
139139
for i in range(cols):
140140
table.add_column()
141141
for i in range(rows):
@@ -161,7 +161,7 @@ def tables(self):
161161
A sequence containing all the tables in the document, in the order
162162
they appear.
163163
"""
164-
return [Table(tbl) for tbl in self._body.tbl_lst]
164+
return [Table(tbl, self) for tbl in self._body.tbl_lst]
165165

166166

167167
class InlineShapes(Parented):

docx/table.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,16 @@
66

77
from __future__ import absolute_import, print_function, unicode_literals
88

9-
from .shared import lazyproperty, write_only_property
9+
from .shared import lazyproperty, Parented, write_only_property
1010
from .text import Paragraph
1111

1212

13-
class Table(object):
13+
class Table(Parented):
1414
"""
1515
Proxy class for a WordprocessingML ``<w:tbl>`` element.
1616
"""
17-
def __init__(self, tbl):
18-
super(Table, self).__init__()
17+
def __init__(self, tbl, parent):
18+
super(Table, self).__init__(parent)
1919
self._tbl = tbl
2020

2121
def add_column(self):

tests/test_table.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,14 @@ def it_can_apply_a_table_style_by_name(self, table_style_set_fixture):
6565
@pytest.fixture
6666
def add_column_fixture(self):
6767
tbl = _tbl_bldr(2, 1).element
68-
table = Table(tbl)
68+
table = Table(tbl, None)
6969
expected_xml = _tbl_bldr(2, 2).xml()
7070
return table, expected_xml
7171

7272
@pytest.fixture
7373
def add_row_fixture(self):
7474
tbl = _tbl_bldr(rows=1, cols=2).element
75-
table = Table(tbl)
75+
table = Table(tbl, None)
7676
expected_xml = _tbl_bldr(rows=2, cols=2).xml()
7777
return table, expected_xml
7878

@@ -82,7 +82,7 @@ def add_row_fixture(self):
8282
])
8383
def table_style_get_fixture(self, request):
8484
tbl_cxml, expected_style = request.param
85-
table = Table(element(tbl_cxml))
85+
table = Table(element(tbl_cxml), None)
8686
return table, expected_style
8787

8888
@pytest.fixture(params=[
@@ -97,7 +97,7 @@ def table_style_get_fixture(self, request):
9797
])
9898
def table_style_set_fixture(self, request):
9999
tbl_cxml, new_style, expected_cxml = request.param
100-
table = Table(element(tbl_cxml))
100+
table = Table(element(tbl_cxml), None)
101101
expected_xml = xml(expected_cxml)
102102
return table, new_style, expected_xml
103103

@@ -106,7 +106,7 @@ def table_style_set_fixture(self, request):
106106
@pytest.fixture
107107
def table(self):
108108
tbl = _tbl_bldr(rows=2, cols=2).element
109-
table = Table(tbl)
109+
table = Table(tbl, None)
110110
return table
111111

112112

0 commit comments

Comments
 (0)