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

Skip to content

Commit ada86c3

Browse files
committed
rfctr: extract default .docx template to directory
Maintaining the default document template as a directory allows its individual parts (XML files) to be curated like code, with line-changes tracked by Git. Extract the default template to a directory and load that directory as the default when no template document is specified to the `Document()` constructor. Also add Header and Footer styles.
1 parent 5a31034 commit ada86c3

File tree

21 files changed

+24393
-2
lines changed

21 files changed

+24393
-2
lines changed

docx/api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,4 @@ def _default_docx_path():
3434
Return the path to the built-in default .docx package.
3535
"""
3636
_thisdir = os.path.split(__file__)[0]
37-
return os.path.join(_thisdir, 'templates', 'default.docx')
37+
return os.path.join(_thisdir, 'templates', 'default-docx-template')

docx/styles/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ class BabelFish(object):
1616
"""
1717

1818
style_aliases = (
19-
('Caption', 'caption'),
19+
('Caption', 'caption'),
20+
('Footer', 'footer'),
21+
('Header', 'header'),
2022
('Heading 1', 'heading 1'),
2123
('Heading 2', 'heading 2'),
2224
('Heading 3', 'heading 3'),
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version='1.0' encoding='UTF-8' standalone='yes'?>
2+
<Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types">
3+
<Default Extension="xml" ContentType="application/xml"/>
4+
<Default Extension="rels" ContentType="application/vnd.openxmlformats-package.relationships+xml"/>
5+
<Default Extension="jpeg" ContentType="image/jpeg"/>
6+
<Override PartName="/word/document.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml"/>
7+
<Override PartName="/customXml/itemProps1.xml" ContentType="application/vnd.openxmlformats-officedocument.customXmlProperties+xml"/>
8+
<Override PartName="/word/numbering.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.numbering+xml"/>
9+
<Override PartName="/word/styles.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.styles+xml"/>
10+
<Override PartName="/word/stylesWithEffects.xml" ContentType="application/vnd.ms-word.stylesWithEffects+xml"/>
11+
<Override PartName="/word/settings.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.settings+xml"/>
12+
<Override PartName="/word/webSettings.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.webSettings+xml"/>
13+
<Override PartName="/word/fontTable.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.fontTable+xml"/>
14+
<Override PartName="/word/theme/theme1.xml" ContentType="application/vnd.openxmlformats-officedocument.theme+xml"/>
15+
<Override PartName="/docProps/core.xml" ContentType="application/vnd.openxmlformats-package.core-properties+xml"/>
16+
<Override PartName="/docProps/app.xml" ContentType="application/vnd.openxmlformats-officedocument.extended-properties+xml"/>
17+
</Types>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version='1.0' encoding='UTF-8' standalone='yes'?>
2+
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
3+
<Relationship Id="rId3" Type="http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties" Target="docProps/core.xml"/>
4+
<Relationship Id="rId4" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties" Target="docProps/app.xml"/>
5+
<Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" Target="word/document.xml"/>
6+
<Relationship Id="rId2" Type="http://schemas.openxmlformats.org/package/2006/relationships/metadata/thumbnail" Target="docProps/thumbnail.jpeg"/>
7+
</Relationships>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version='1.0' encoding='UTF-8' standalone='yes'?>
2+
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
3+
<Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/customXmlProps" Target="itemProps1.xml"/>
4+
</Relationships>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<?xml version='1.0' encoding='UTF-8' standalone='yes'?>
2+
<b:Sources xmlns:b="http://schemas.openxmlformats.org/officeDocument/2006/bibliography" xmlns="http://schemas.openxmlformats.org/officeDocument/2006/bibliography" SelectedStyle="/APA.XSL" StyleName="APA"/>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version='1.0' encoding='UTF-8' standalone='yes'?>
2+
<ds:datastoreItem xmlns:ds="http://schemas.openxmlformats.org/officeDocument/2006/customXml" ds:itemID="{EF278816-EC6F-A645-907D-7F25AECB1D4A}">
3+
<ds:schemaRefs>
4+
<ds:schemaRef ds:uri="http://schemas.openxmlformats.org/officeDocument/2006/bibliography"/>
5+
</ds:schemaRefs>
6+
</ds:datastoreItem>
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?xml version='1.0' encoding='UTF-8' standalone='yes'?>
2+
<Properties xmlns="http://schemas.openxmlformats.org/officeDocument/2006/extended-properties" xmlns:vt="http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes">
3+
<Template>Normal.dotm</Template>
4+
<TotalTime>0</TotalTime>
5+
<Pages>1</Pages>
6+
<Words>0</Words>
7+
<Characters>0</Characters>
8+
<Application>Microsoft Macintosh Word</Application>
9+
<DocSecurity>0</DocSecurity>
10+
<Lines>0</Lines>
11+
<Paragraphs>0</Paragraphs>
12+
<ScaleCrop>false</ScaleCrop>
13+
<HeadingPairs>
14+
<vt:vector size="2" baseType="variant">
15+
<vt:variant>
16+
<vt:lpstr>Title</vt:lpstr>
17+
</vt:variant>
18+
<vt:variant>
19+
<vt:i4>1</vt:i4>
20+
</vt:variant>
21+
</vt:vector>
22+
</HeadingPairs>
23+
<TitlesOfParts>
24+
<vt:vector size="1" baseType="lpstr">
25+
<vt:lpstr/>
26+
</vt:vector>
27+
</TitlesOfParts>
28+
<Manager/>
29+
<Company/>
30+
<LinksUpToDate>false</LinksUpToDate>
31+
<CharactersWithSpaces>0</CharactersWithSpaces>
32+
<SharedDoc>false</SharedDoc>
33+
<HyperlinkBase/>
34+
<HyperlinksChanged>false</HyperlinksChanged>
35+
<AppVersion>14.0000</AppVersion>
36+
</Properties>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version='1.0' encoding='UTF-8' standalone='yes'?>
2+
<cp:coreProperties xmlns:cp="http://schemas.openxmlformats.org/package/2006/metadata/core-properties" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dcterms="http://purl.org/dc/terms/" xmlns:dcmitype="http://purl.org/dc/dcmitype/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
3+
<dc:title/>
4+
<dc:subject/>
5+
<dc:creator>python-docx</dc:creator>
6+
<cp:keywords/>
7+
<dc:description>generated by python-docx</dc:description>
8+
<cp:lastModifiedBy/>
9+
<cp:revision>1</cp:revision>
10+
<dcterms:created xsi:type="dcterms:W3CDTF">2013-12-23T23:15:00Z</dcterms:created>
11+
<dcterms:modified xsi:type="dcterms:W3CDTF">2013-12-23T23:15:00Z</dcterms:modified>
12+
<cp:category/>
13+
</cp:coreProperties>
8.13 KB
Loading

0 commit comments

Comments
 (0)