Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/docx/opc/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,10 @@ class RELATIONSHIP_TYPE:
"http://schemas.openxmlformats.org/package/2006/relationships/metada"
"ta/core-properties"
)
CORE_PROPERTIES_OFFICEDOCUMENT = (
"http://schemas.openxmlformats.org/officedocument/2006/relationships"
"/metadata/core-properties"
)
CUSTOM_PROPERTIES = (
"http://schemas.openxmlformats.org/officeDocument/2006/relationships"
"/custom-properties"
Expand Down
12 changes: 9 additions & 3 deletions src/docx/opc/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,15 @@ def _core_properties_part(self) -> CorePropertiesPart:
try:
return cast(CorePropertiesPart, self.part_related_by(RT.CORE_PROPERTIES))
except KeyError:
core_properties_part = CorePropertiesPart.default(self)
self.relate_to(core_properties_part, RT.CORE_PROPERTIES)
return core_properties_part
try:
office_document_part = self.part_related_by(RT.CORE_PROPERTIES_OFFICEDOCUMENT)
rel = self.relate_to(office_document_part, RT.CORE_PROPERTIES_OFFICEDOCUMENT)
self.rels[rel].set_reltype(RT.CORE_PROPERTIES)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First see below how to create a setter. Then change this line to

self.rels[rel].reltype = RT.CORE_PROPERTIES

return cast(CorePropertiesPart, office_document_part)
except KeyError:
core_properties_part = CorePropertiesPart.default(self)
self.relate_to(core_properties_part, RT.CORE_PROPERTIES)
return core_properties_part


class Unmarshaller:
Expand Down
3 changes: 3 additions & 0 deletions src/docx/opc/rel.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@ def is_external(self) -> bool:
def reltype(self) -> str:
return self._reltype

def set_reltype(self, reltype:str) -> None:
self._reltype = reltype
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be a setter

    @reltype.setter
    def reltype(self, value: str):
        self._reltype = value


@property
def rId(self) -> str:
return self._rId
Expand Down