Skip to content

Commit eb48298

Browse files
committed
hdr: add _Footer._has_definition
1 parent 14bbaf2 commit eb48298

File tree

4 files changed

+37
-1
lines changed

4 files changed

+37
-1
lines changed

docx/oxml/section.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,14 @@ def footer(self, value):
124124
pgMar = self.get_or_add_pgMar()
125125
pgMar.footer = value
126126

127+
def get_footerReference(self, type_):
128+
"""Return footerReference element of *type_* or None if not present."""
129+
path = "./w:footerReference[@w:type='%s']" % WD_HEADER_FOOTER.to_xml(type_)
130+
footerReferences = self.xpath(path)
131+
if not footerReferences:
132+
return None
133+
return footerReferences[0]
134+
127135
def get_headerReference(self, type_):
128136
"""Return headerReference element of *type_* or None if not present."""
129137
matching_headerReferences = self.xpath(

docx/section.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,12 @@ def _has_definition(self):
241241
class _Footer(_BaseHeaderFooter):
242242
"""Page footer."""
243243

244+
@property
245+
def _has_definition(self):
246+
"""True if a footer is defined for this section."""
247+
footerReference = self._sectPr.get_footerReference(WD_HEADER_FOOTER.PRIMARY)
248+
return False if footerReference is None else True
249+
244250

245251
class _Header(_BaseHeaderFooter):
246252
"""Page header."""

features/hdr-header-footer.feature

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ Feature: Header and footer behaviors
3434
And header_2.is_linked_to_previous is True
3535

3636

37-
@wip
3837
Scenario Outline: _Footer.is_linked_to_previous getter
3938
Given a _Footer object <with-or-no> footer definition as footer
4039
Then footer.is_linked_to_previous is <value>

tests/test_section.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,29 @@ def _has_definition_prop_(self, request):
385385
return property_mock(request, _BaseHeaderFooter, "_has_definition")
386386

387387

388+
class Describe_Footer(object):
389+
390+
def it_knows_when_it_has_a_definition_to_help(self, has_definition_fixture):
391+
sectPr, expected_value = has_definition_fixture
392+
footer = _Footer(sectPr, None)
393+
394+
has_definition = footer._has_definition
395+
396+
assert has_definition is expected_value
397+
398+
# fixtures -------------------------------------------------------
399+
400+
@pytest.fixture(
401+
params=[
402+
("w:sectPr", False), ("w:sectPr/w:footerReference{w:type=default}", True)
403+
]
404+
)
405+
def has_definition_fixture(self, request):
406+
sectPr_cxml, expected_value = request.param
407+
sectPr = element(sectPr_cxml)
408+
return sectPr, expected_value
409+
410+
388411
class Describe_Header(object):
389412

390413
def it_knows_when_its_linked_to_the_previous_header(

0 commit comments

Comments
 (0)