Skip to content

Settings

Representation of the “settings.xml” part of the ODF document.

This part stores document-wide settings.

Classes:

Name Description
Settings

Representation of the “settings.xml” part of the ODF document.

Settings

Bases: XmlPart

Representation of the “settings.xml” part of the ODF document.

This part stores document-wide settings.

Methods:

Name Description
as_dict

Serialize the settings content into a dictionary.

Attributes:

Name Type Description
config_item_sets list[ConfigItemSet]

Get a list of first-level ConfigItemSet elements within the

odf_office_version str

Get the “office:version” value of the settings part.

Source code in odfdo/settings.py
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
class Settings(XmlPart):
    """Representation of the "settings.xml" part of the ODF document.

    This part stores document-wide settings.
    """

    def _get_body(self) -> OfficeSettings:
        body = cast(None | OfficeSettings, self.get_element("//office:settings"))
        if isinstance(body, OfficeSettings):
            return body
        raise TypeError("No OfficeSettings found")  # pragma: nocover

    @property
    def odf_office_version(self) -> str:
        """Get the "office:version" value of the settings part.

        This value indicates the ODF version of the document settings.

        Returns:
            str: The "office:version" value, or an empty string if not found.
        """
        odsettings = cast(
            None | Element, self.get_element("//office:document-settings")
        )
        # "office:version" should be always present
        if odsettings:
            return odsettings.get_attribute_string("office:version") or ""
        return ""  # pragma: nocover

    @property
    def config_item_sets(self) -> list[ConfigItemSet]:
        """Get a list of first-level ConfigItemSet elements within the
        settings.

        These represent top-level configuration item sets in the document's
        settings.

        Returns:
        list[ConfigItemSet]: A list of `ConfigItemSet` objects.
        """
        return cast(
            list[ConfigItemSet], self.body.get_elements("config:config-item-set")
        )

    def as_dict(self) -> dict[str, str | int | bool | dict[str, Any] | list[Any]]:
        """Serialize the settings content into a dictionary.

        This method delegates the serialization to the underlying
        `OfficeSettings` body, returning a dictionary representation of
        the settings.

        Returns:
            dict: A dictionary representing the settings content.
        """
        body: OfficeSettings = cast(OfficeSettings, self.body)
        return body.as_dict()

config_item_sets property

config_item_sets: list[ConfigItemSet]

Get a list of first-level ConfigItemSet elements within the settings.

These represent top-level configuration item sets in the document’s settings.

Returns: list[ConfigItemSet]: A list of ConfigItemSet objects.

odf_office_version property

odf_office_version: str

Get the “office:version” value of the settings part.

This value indicates the ODF version of the document settings.

Returns:

Name Type Description
str str

The “office:version” value, or an empty string if not found.

_get_body

_get_body() -> OfficeSettings
Source code in odfdo/settings.py
41
42
43
44
45
def _get_body(self) -> OfficeSettings:
    body = cast(None | OfficeSettings, self.get_element("//office:settings"))
    if isinstance(body, OfficeSettings):
        return body
    raise TypeError("No OfficeSettings found")  # pragma: nocover

as_dict

as_dict() -> dict[
    str, str | int | bool | dict[str, Any] | list[Any]
]

Serialize the settings content into a dictionary.

This method delegates the serialization to the underlying OfficeSettings body, returning a dictionary representation of the settings.

Returns:

Name Type Description
dict dict[str, str | int | bool | dict[str, Any] | list[Any]]

A dictionary representing the settings content.

Source code in odfdo/settings.py
79
80
81
82
83
84
85
86
87
88
89
90
def as_dict(self) -> dict[str, str | int | bool | dict[str, Any] | list[Any]]:
    """Serialize the settings content into a dictionary.

    This method delegates the serialization to the underlying
    `OfficeSettings` body, returning a dictionary representation of
    the settings.

    Returns:
        dict: A dictionary representing the settings content.
    """
    body: OfficeSettings = cast(OfficeSettings, self.body)
    return body.as_dict()