Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 11e0fb3

Browse files
committed
hdr: add FooterPart._default_footer_xml()
1 parent 64e9836 commit 11e0fb3

File tree

4 files changed

+42
-2
lines changed

4 files changed

+42
-2
lines changed

docx/parts/hdrftr.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,12 @@ def new(cls, package):
2525
@classmethod
2626
def _default_footer_xml(cls):
2727
"""Return bytes containing XML for a default footer part."""
28-
raise NotImplementedError
28+
path = os.path.join(
29+
os.path.split(__file__)[0], '..', 'templates', 'default-footer.xml'
30+
)
31+
with open(path, 'rb') as f:
32+
xml_bytes = f.read()
33+
return xml_bytes
2934

3035

3136
class HeaderPart(XmlPart):

docx/templates/default-footer.xml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?xml version='1.0' encoding='UTF-8' standalone='yes'?>
2+
<w:ftr
3+
xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math"
4+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
5+
xmlns:mo="http://schemas.microsoft.com/office/mac/office/2008/main"
6+
xmlns:mv="urn:schemas-microsoft-com:mac:vml"
7+
xmlns:o="urn:schemas-microsoft-com:office:office"
8+
xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships"
9+
xmlns:v="urn:schemas-microsoft-com:vml"
10+
xmlns:w10="urn:schemas-microsoft-com:office:word"
11+
xmlns:w14="http://schemas.microsoft.com/office/word/2010/wordml"
12+
xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"
13+
xmlns:wne="http://schemas.microsoft.com/office/word/2006/wordml"
14+
xmlns:wp14="http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing"
15+
xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing"
16+
xmlns:wpc="http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas"
17+
xmlns:wpg="http://schemas.microsoft.com/office/word/2010/wordprocessingGroup"
18+
xmlns:wpi="http://schemas.microsoft.com/office/word/2010/wordprocessingInk"
19+
xmlns:wps="http://schemas.microsoft.com/office/word/2010/wordprocessingShape"
20+
mc:Ignorable="w14 wp14"
21+
>
22+
<w:p>
23+
<w:pPr>
24+
<w:pStyle w:val="Footer"/>
25+
</w:pPr>
26+
</w:p>
27+
</w:ftr>

features/hdr-header-footer.feature

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ Feature: Header and footer behaviors
4444
| with no | True |
4545

4646

47-
@wip
4847
Scenario Outline: _Footer.is_linked_to_previous setter
4948
Given a _Footer object <with-or-no> footer definition as footer
5049
When I assign <value> to footer.is_linked_to_previous

tests/parts/test_hdrftr.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,15 @@ def it_can_create_a_new_footer_part(
3434
footer_part, "/word/footer24.xml", CT.WML_FOOTER, ftr, package_
3535
)
3636

37+
def it_loads_default_footer_XML_from_a_template_to_help(self):
38+
# ---tests integration with OS---
39+
xml_bytes = FooterPart._default_footer_xml()
40+
41+
assert xml_bytes.startswith(
42+
b"<?xml version='1.0' encoding='UTF-8' standalone='yes'?>\n<w:ftr\n"
43+
)
44+
assert len(xml_bytes) == 1395
45+
3746
# fixture components ---------------------------------------------
3847

3948
@pytest.fixture

0 commit comments

Comments
 (0)