Skip to content

Commit

Permalink
Corrected the creation of picrelid and unique filenames, usage of
Browse files Browse the repository at this point in the history
picdescription instead of picname in creating the cNvPr element, and
removed an invalid reference from the template.
  • Loading branch information
reinspijkerman authored and Steve Canny committed Dec 14, 2013
1 parent 2b63b96 commit f0b4318
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
13 changes: 7 additions & 6 deletions docx.py
Original file line number Diff line number Diff line change
Expand Up @@ -447,14 +447,14 @@ def picture(
if imagefiledict is not None:
# Keep track of the image files in a separate dictionary so they don't
# need to be copied into the template directory

if picpath not in imagefiledict:
picrelid = 'rId' + str(len(imagefiledict.keys()) + 1)
picrelid = 'rId' + str(len(relationshiplist) + 1)
imagefiledict[picpath] = picrelid

relationshiplist.append([
'http://schemas.openxmlformats.org/officeDocument/2006/relat'
'ionships/image', 'media/' + basename(picpath)
'ionships/image',
'media/%s_%s' % (picrelid, basename(picpath))
])
else:
picrelid = imagefiledict[picpath]
Expand Down Expand Up @@ -522,7 +522,8 @@ def picture(
nvpicpr = makeelement('nvPicPr', nsprefix='pic')
cnvpr = makeelement(
'cNvPr', nsprefix='pic',
attributes={'id': '0', 'name': 'Picture 1', 'descr': picname})
attributes={'id': '0', 'name': 'Picture 1', 'descr': picdescription}
)
nvpicpr.append(cnvpr)
cnvpicpr = makeelement('cNvPicPr', nsprefix='pic')
cnvpicpr.append(makeelement(
Expand Down Expand Up @@ -1066,8 +1067,8 @@ def savedocx(

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

Expand Down
2 changes: 0 additions & 2 deletions template/_rels/.rels
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,4 @@

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

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

</Relationships>

0 comments on commit f0b4318

Please sign in to comment.