Skip to content

Commit d3b8eb7

Browse files
ondrej-111scanny
authored andcommitted
sect: add Section.footer
1 parent 7c64652 commit d3b8eb7

File tree

4 files changed

+49
-2
lines changed

4 files changed

+49
-2
lines changed

docs/conf.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@
107107
108108
.. |Font| replace:: :class:`.Font`
109109
110+
.. |_Footer| replace:: :class:`._Footer`
111+
110112
.. |_Header| replace:: :class:`._Header`
111113
112114
.. |ImageParts| replace:: :class:`.ImageParts`

docx/section.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66

77
from collections import Sequence
88

9+
from docx.blkcntnr import BlockItemContainer
10+
from docx.shared import lazyproperty
11+
912

1013
class Sections(Sequence):
1114
"""Sequence of |Section| objects corresponding to the sections in the document.
@@ -57,6 +60,15 @@ def bottom_margin(self):
5760
def bottom_margin(self, value):
5861
self._sectPr.bottom_margin = value
5962

63+
@lazyproperty
64+
def footer(self):
65+
"""|_Footer| object representing default page footer for this section.
66+
67+
The default footer is used for odd-numbered pages when separate odd/even footers
68+
are enabled. It is used for both odd and even-numbered pages otherwise.
69+
"""
70+
return _Footer(self._sectPr, self._document_part)
71+
6072
@property
6173
def footer_distance(self):
6274
"""
@@ -187,3 +199,11 @@ def top_margin(self):
187199
@top_margin.setter
188200
def top_margin(self, value):
189201
self._sectPr.top_margin = value
202+
203+
204+
class _Footer(BlockItemContainer):
205+
"""Page footer."""
206+
207+
def __init__(self, sectPr, document_part):
208+
self._sectPr = sectPr
209+
self._document_part = document_part

features/sct-section.feature

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ Feature: Access and change section properties
44
I need a way to get and set the properties of a section
55

66

7-
@wip
87
Scenario: Section.footer
98
Given a Section object as section
109
Then section.footer is a _Footer object

tests/test_section.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
from docx.enum.section import WD_ORIENT, WD_SECTION
1010
from docx.parts.document import DocumentPart
11-
from docx.section import Section, Sections
11+
from docx.section import _Footer, Section, Sections
1212
from docx.shared import Inches
1313

1414
from .unitutil.cxml import element, xml
@@ -91,6 +91,18 @@ def section_(self, request):
9191

9292
class DescribeSection(object):
9393

94+
def it_provides_access_to_its_default_footer(
95+
self, document_part_, _Footer_, footer_
96+
):
97+
sectPr = element('w:sectPr')
98+
_Footer_.return_value = footer_
99+
section = Section(sectPr, document_part_)
100+
101+
footer = section.footer
102+
103+
_Footer_.assert_called_once_with(sectPr, document_part_)
104+
assert footer is footer_
105+
94106
def it_knows_its_start_type(self, start_type_get_fixture):
95107
sectPr, expected_start_type = start_type_get_fixture
96108
section = Section(sectPr, None)
@@ -309,3 +321,17 @@ def start_type_set_fixture(self, request):
309321
sectPr = element(initial_cxml)
310322
expected_xml = xml(expected_cxml)
311323
return sectPr, new_start_type, expected_xml
324+
325+
# fixture components ---------------------------------------------
326+
327+
@pytest.fixture
328+
def document_part_(self, request):
329+
return instance_mock(request, DocumentPart)
330+
331+
@pytest.fixture
332+
def _Footer_(self, request):
333+
return class_mock(request, "docx.section._Footer")
334+
335+
@pytest.fixture
336+
def footer_(self, request):
337+
return instance_mock(request, _Footer)

0 commit comments

Comments
 (0)