Skip to content

Meta Template

MetaTemplate class for “meta:template” tag.

Classes:

Name Description
MetaTemplate

Container for the meta template properties, “meta:template”.

MetaTemplate

Bases: Element

Container for the meta template properties, “meta:template”.

Methods:

Name Description
__init__

Initialize a MetaTemplate element.

__repr__
__str__
as_dict

Return the attributes of the template element as a Python dictionary.

from_dict

Set the attributes of the template element from a Python dictionary.

Attributes:

Name Type Description
actuate
href
title
type
Source code in odfdo/meta_template.py
 31
 32
 33
 34
 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
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
class MetaTemplate(Element):
    """Container for the meta template properties, "meta:template"."""

    _tag = "meta:template"
    _properties: tuple[PropDef | PropDefBool, ...] = (
        PropDef("date", "meta:date"),
        PropDef("actuate", "xlink:actuate"),
        PropDef("href", "xlink:href"),
        PropDef("title", "xlink:title"),
        PropDef("type", "xlink:type"),
    )

    def __init__(
        self,
        date: datetime | None = None,
        href: str = "",
        title: str = "",
        **kwargs: Any,
    ) -> None:
        """Initialize a MetaTemplate element.

        The `meta:template` element specifies a URI for the document template
        that was used to create a document. The URI is specified as an XLink.

        Args:
            date: The date and time when the template was used.
            href: The URI for the document template (XLink).
            title: The title of the document template (XLink).
            **kwargs: Additional keyword arguments for the parent `Element` class.
        """
        super().__init__(**kwargs)

        self.actuate = "onRequest"
        self.type = "simple"
        if self._do_init:
            self._set_date(date)
            self.href = href
            self.title = title

    def __repr__(self) -> str:
        return f"<{self.__class__.__name__} tag={self.tag} href={self.href}>"

    def __str__(self) -> str:
        if self.title:
            return f"[{self.title}]({self.href})"
        return f"({self.href})"

    def _set_date(self, date: datetime | None) -> None:
        """Set the `meta:date` attribute from a `datetime` object.

        Converts the `datetime` to an ODF date-time string. If `date` is
        None, it defaults to the current UTC time.

        Args:
            date: The date and time to set.
        """
        if date is None:
            date = datetime.now()
        self.date = DateTime.encode(date)

    def as_dict(self) -> dict[str, Any]:
        """Return the attributes of the template element as a Python dictionary.

        Returns:
            dict[str, Any]: A dictionary containing the meta template
                attributes, with keys like "meta:date", "xlink:href", etc.
        """
        result: dict[str, Any] = {}
        if self.date:
            result["meta:date"] = DateTime.decode(self.date)
        result.update(
            {
                "xlink:actuate": self.actuate or "",
                "xlink:href": self.href or "",
                "xlink:title": self.title or "",
                "xlink:type": self.type or "",
            }
        )
        return result

    def from_dict(self, data: dict[str, Any]) -> None:
        """Set the attributes of the template element from a Python dictionary.

        Args:
            data: A dictionary containing the meta template
                attributes (e.g., "meta:date", "xlink:href").
        """
        self._set_date(data.get("meta:date"))
        self.actuate = data.get("xlink:actuate", "onRequest")
        self.href = data.get("xlink:href", "")
        self.title = data.get("xlink:title", "")
        self.type = data.get("xlink:type", "simple")

_properties class-attribute instance-attribute

_properties: tuple[PropDef | PropDefBool, ...] = (
    PropDef("date", "meta:date"),
    PropDef("actuate", "xlink:actuate"),
    PropDef("href", "xlink:href"),
    PropDef("title", "xlink:title"),
    PropDef("type", "xlink:type"),
)

_tag class-attribute instance-attribute

_tag = 'meta:template'

actuate instance-attribute

actuate = 'onRequest'

href instance-attribute

href = href

title instance-attribute

title = title

type instance-attribute

type = 'simple'

__init__

__init__(
    date: datetime | None = None,
    href: str = "",
    title: str = "",
    **kwargs: Any,
) -> None

Initialize a MetaTemplate element.

The meta:template element specifies a URI for the document template that was used to create a document. The URI is specified as an XLink.

Parameters:

Name Type Description Default
date datetime | None

The date and time when the template was used.

None
href str

The URI for the document template (XLink).

''
title str

The title of the document template (XLink).

''
**kwargs Any

Additional keyword arguments for the parent Element class.

{}
Source code in odfdo/meta_template.py
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
def __init__(
    self,
    date: datetime | None = None,
    href: str = "",
    title: str = "",
    **kwargs: Any,
) -> None:
    """Initialize a MetaTemplate element.

    The `meta:template` element specifies a URI for the document template
    that was used to create a document. The URI is specified as an XLink.

    Args:
        date: The date and time when the template was used.
        href: The URI for the document template (XLink).
        title: The title of the document template (XLink).
        **kwargs: Additional keyword arguments for the parent `Element` class.
    """
    super().__init__(**kwargs)

    self.actuate = "onRequest"
    self.type = "simple"
    if self._do_init:
        self._set_date(date)
        self.href = href
        self.title = title

__repr__

__repr__() -> str
Source code in odfdo/meta_template.py
70
71
def __repr__(self) -> str:
    return f"<{self.__class__.__name__} tag={self.tag} href={self.href}>"

__str__

__str__() -> str
Source code in odfdo/meta_template.py
73
74
75
76
def __str__(self) -> str:
    if self.title:
        return f"[{self.title}]({self.href})"
    return f"({self.href})"

_set_date

_set_date(date: datetime | None) -> None

Set the meta:date attribute from a datetime object.

Converts the datetime to an ODF date-time string. If date is None, it defaults to the current UTC time.

Parameters:

Name Type Description Default
date datetime | None

The date and time to set.

required
Source code in odfdo/meta_template.py
78
79
80
81
82
83
84
85
86
87
88
89
def _set_date(self, date: datetime | None) -> None:
    """Set the `meta:date` attribute from a `datetime` object.

    Converts the `datetime` to an ODF date-time string. If `date` is
    None, it defaults to the current UTC time.

    Args:
        date: The date and time to set.
    """
    if date is None:
        date = datetime.now()
    self.date = DateTime.encode(date)

as_dict

as_dict() -> dict[str, Any]

Return the attributes of the template element as a Python dictionary.

Returns:

Type Description
dict[str, Any]

dict[str, Any]: A dictionary containing the meta template attributes, with keys like “meta:date”, “xlink:href”, etc.

Source code in odfdo/meta_template.py
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
def as_dict(self) -> dict[str, Any]:
    """Return the attributes of the template element as a Python dictionary.

    Returns:
        dict[str, Any]: A dictionary containing the meta template
            attributes, with keys like "meta:date", "xlink:href", etc.
    """
    result: dict[str, Any] = {}
    if self.date:
        result["meta:date"] = DateTime.decode(self.date)
    result.update(
        {
            "xlink:actuate": self.actuate or "",
            "xlink:href": self.href or "",
            "xlink:title": self.title or "",
            "xlink:type": self.type or "",
        }
    )
    return result

from_dict

from_dict(data: dict[str, Any]) -> None

Set the attributes of the template element from a Python dictionary.

Parameters:

Name Type Description Default
data dict[str, Any]

A dictionary containing the meta template attributes (e.g., “meta:date”, “xlink:href”).

required
Source code in odfdo/meta_template.py
111
112
113
114
115
116
117
118
119
120
121
122
def from_dict(self, data: dict[str, Any]) -> None:
    """Set the attributes of the template element from a Python dictionary.

    Args:
        data: A dictionary containing the meta template
            attributes (e.g., "meta:date", "xlink:href").
    """
    self._set_date(data.get("meta:date"))
    self.actuate = data.get("xlink:actuate", "onRequest")
    self.href = data.get("xlink:href", "")
    self.title = data.get("xlink:title", "")
    self.type = data.get("xlink:type", "simple")