Skip to content
This repository was archived by the owner on Jan 12, 2018. It is now read-only.

Commit f0b4318

Browse files
reinspijkermanSteve Canny
authored andcommitted
Corrected the creation of picrelid and unique filenames, usage of
picdescription instead of picname in creating the cNvPr element, and removed an invalid reference from the template.
1 parent 2b63b96 commit f0b4318

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

docx.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -447,14 +447,14 @@ def picture(
447447
if imagefiledict is not None:
448448
# Keep track of the image files in a separate dictionary so they don't
449449
# need to be copied into the template directory
450-
451450
if picpath not in imagefiledict:
452-
picrelid = 'rId' + str(len(imagefiledict.keys()) + 1)
451+
picrelid = 'rId' + str(len(relationshiplist) + 1)
453452
imagefiledict[picpath] = picrelid
454453

455454
relationshiplist.append([
456455
'http://schemas.openxmlformats.org/officeDocument/2006/relat'
457-
'ionships/image', 'media/' + basename(picpath)
456+
'ionships/image',
457+
'media/%s_%s' % (picrelid, basename(picpath))
458458
])
459459
else:
460460
picrelid = imagefiledict[picpath]
@@ -522,7 +522,8 @@ def picture(
522522
nvpicpr = makeelement('nvPicPr', nsprefix='pic')
523523
cnvpr = makeelement(
524524
'cNvPr', nsprefix='pic',
525-
attributes={'id': '0', 'name': 'Picture 1', 'descr': picname})
525+
attributes={'id': '0', 'name': 'Picture 1', 'descr': picdescription}
526+
)
526527
nvpicpr.append(cnvpr)
527528
cnvpicpr = makeelement('cNvPicPr', nsprefix='pic')
528529
cnvpicpr.append(makeelement(
@@ -1066,8 +1067,8 @@ def savedocx(
10661067

10671068
# Add & compress images, if applicable
10681069
if imagefiledict is not None:
1069-
for imagepath in imagefiledict.keys():
1070-
archivename = 'word/media/' + basename(imagepath)
1070+
for imagepath, picrelid in imagefiledict.items():
1071+
archivename = 'word/media/%s_%s' % (picrelid, basename(imagepath))
10711072
log.info('Saving: %s', archivename)
10721073
docxfile.write(imagepath, archivename)
10731074

template/_rels/.rels

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,4 @@
99

1010
<Relationship Id="rId3" Type="http://schemas.openxmlformats.org/officedocument/2006/relationships/metadata/core-properties" Target="docProps/core.xml"/>
1111

12-
<Relationship Id="rId7" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/image" Target="media/image1.png"/>
13-
1412
</Relationships>

0 commit comments

Comments
 (0)