Skip to content

Form Controls Mixins

Mixin classes for Form controls.

(The main objective of the current minimal implementation of forms is to parse the existing form contents in a document.)

Classes:

Name Description
FormAsDictMixin

Mixin for the as_dict() method of Form Control classes.

FormButtonTypeMixin

Mixin for the “form:button-type” attribute.

FormDelayRepeatMixin

Mixin for the “form:delay-for-repeat” attribute.

FormImageAlignMixin

Mixin for the “form:image-align” attribute.

FormImagePositionMixin

Mixin for the “form:image-position” attribute.

FormMaxLengthMixin

Mixin for the “form:max-length” attribute.

FormSizetMixin

Mixin for the “form:size” attribute.

FormSourceListMixin

Mixin for the “form:list-source-type” attribute.

OfficeTargetFrameMixin

Mixin for the “office:target-frame” attribute.

FormAsDictMixin

Mixin for the as_dict() method of Form Control classes.

Methods:

Name Description
as_dict

Serialize the Form content as a Python dict.

Source code in odfdo/form_controls_mixins.py
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
class FormAsDictMixin:
    """Mixin for the as_dict() method of Form Control classes."""

    def as_dict(self) -> dict[str, str | Decimal | int | None]:
        """Serialize the Form content as a Python dict.

        Returns:
            The Form content as a Python dict.
        """
        return {
            "tag": self.tag,  # type: ignore[attr-defined]
            "name": self.name,  # type: ignore[attr-defined]
            "xml_id": self.xml_id,  # type: ignore[attr-defined]
            "value": self.value,  # type: ignore[attr-defined]
            "current_value": self.current_value
            if hasattr(self, "current_value")
            else None,
            "str": str(self),
        }

as_dict

as_dict() -> dict[str, str | Decimal | int | None]

Serialize the Form content as a Python dict.

Returns:

Type Description
dict[str, str | Decimal | int | None]

The Form content as a Python dict.

Source code in odfdo/form_controls_mixins.py
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
def as_dict(self) -> dict[str, str | Decimal | int | None]:
    """Serialize the Form content as a Python dict.

    Returns:
        The Form content as a Python dict.
    """
    return {
        "tag": self.tag,  # type: ignore[attr-defined]
        "name": self.name,  # type: ignore[attr-defined]
        "xml_id": self.xml_id,  # type: ignore[attr-defined]
        "value": self.value,  # type: ignore[attr-defined]
        "current_value": self.current_value
        if hasattr(self, "current_value")
        else None,
        "str": str(self),
    }

FormButtonTypeMixin

Bases: Element

Mixin for the “form:button-type” attribute.

Attributes:

Name Type Description
BUTTON_TYPES set[str]
button_type str | None
Source code in odfdo/form_controls_mixins.py
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
class FormButtonTypeMixin(Element):
    """Mixin for the "form:button-type" attribute."""

    BUTTON_TYPES: ClassVar[set[str]] = {"submit", "reset", "push", "url"}

    @property
    def button_type(self) -> str | None:
        return self._get_attribute_str_default("form:button-type", "push")

    @button_type.setter
    def button_type(self, button_type: str | None) -> None:
        if button_type is None or button_type in self.BUTTON_TYPES:
            self._set_attribute_str_default("form:button-type", button_type, "push")
        else:
            raise ValueError

BUTTON_TYPES class-attribute

BUTTON_TYPES: set[str] = {'submit', 'reset', 'push', 'url'}

button_type property writable

button_type: str | None

FormDelayRepeatMixin

Bases: Element

Mixin for the “form:delay-for-repeat” attribute.

Attributes:

Name Type Description
delay_for_repeat str
Source code in odfdo/form_controls_mixins.py
33
34
35
36
37
38
39
40
41
42
43
44
class FormDelayRepeatMixin(Element):
    """Mixin for the "form:delay-for-repeat" attribute."""

    @property
    def delay_for_repeat(self) -> str:
        return self._get_attribute_str_default("form:delay-for-repeat", "PT0.050S")

    @delay_for_repeat.setter
    def delay_for_repeat(self, delay_for_repeat: str | None) -> None:
        self._set_attribute_str_default(
            "form:delay-for-repeat", delay_for_repeat, "PT0.050S"
        )

delay_for_repeat property writable

delay_for_repeat: str

FormImageAlignMixin

Bases: Element

Mixin for the “form:image-align” attribute.

Attributes:

Name Type Description
IMAGE_ALIGN set[str]
image_align str | None
Source code in odfdo/form_controls_mixins.py
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
class FormImageAlignMixin(Element):
    """Mixin for the "form:image-align" attribute."""

    IMAGE_ALIGN: ClassVar[set[str]] = {"start", "center", "end"}

    @property
    def image_align(self) -> str | None:
        return self._get_attribute_str_default("form:image-align", "center")

    @image_align.setter
    def image_align(self, image_align: str | None) -> None:
        if image_align is None or image_align in self.IMAGE_ALIGN:
            self._set_attribute_str_default("form:image-align", image_align, "center")
        else:
            raise ValueError

IMAGE_ALIGN class-attribute

IMAGE_ALIGN: set[str] = {'start', 'center', 'end'}

image_align property writable

image_align: str | None

FormImagePositionMixin

Bases: Element

Mixin for the “form:image-position” attribute.

Attributes:

Name Type Description
IMAGE_POSITION set[str]
image_position str | None
Source code in odfdo/form_controls_mixins.py
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
class FormImagePositionMixin(Element):
    """Mixin for the "form:image-position" attribute."""

    IMAGE_POSITION: ClassVar[set[str]] = {"bottom", "center", "end", "start", "top"}

    @property
    def image_position(self) -> str | None:
        return self._get_attribute_str_default("form:image-position", "center")

    @image_position.setter
    def image_position(self, image_position: str | None) -> None:
        if image_position is None or image_position in self.IMAGE_POSITION:
            self._set_attribute_str_default(
                "form:image-position", image_position, "center"
            )
        else:
            raise ValueError

IMAGE_POSITION class-attribute

IMAGE_POSITION: set[str] = {
    "bottom",
    "center",
    "end",
    "start",
    "top",
}

image_position property writable

image_position: str | None

FormMaxLengthMixin

Bases: Element

Mixin for the “form:max-length” attribute.

Attributes:

Name Type Description
max_length int | None
Source code in odfdo/form_controls_mixins.py
47
48
49
50
51
52
53
54
55
56
57
58
59
60
class FormMaxLengthMixin(Element):
    """Mixin for the "form:max-length" attribute."""

    @property
    def max_length(self) -> int | None:
        return self.get_attribute_integer("form:max-length")

    @max_length.setter
    def max_length(self, max_length: int | None) -> None:
        if max_length is None:
            self.del_attribute("form:max-length")
        else:
            max_length = max(max_length, 0)
        self._set_attribute_str_default("form:max-length", str(max_length), "")

max_length property writable

max_length: int | None

FormSizetMixin

Bases: Element

Mixin for the “form:size” attribute.

Attributes:

Name Type Description
size int | None
Source code in odfdo/form_controls_mixins.py
110
111
112
113
114
115
116
117
118
119
120
121
122
123
class FormSizetMixin(Element):
    """Mixin for the "form:size" attribute."""

    @property
    def size(self) -> int | None:
        return self.get_attribute_integer("form:size")

    @size.setter
    def size(self, size: int | None) -> None:
        if size is None:
            self.del_attribute("form:size")
        else:
            size = max(size, 0)
        self._set_attribute_str_default("form:size", str(size), "")

size property writable

size: int | None

FormSourceListMixin

Bases: Element

Mixin for the “form:list-source-type” attribute.

Attributes:

Name Type Description
LIST_SOURCE_TYPE set[str]
list_source_type str | None
Source code in odfdo/form_controls_mixins.py
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
class FormSourceListMixin(Element):
    """Mixin for the "form:list-source-type" attribute."""

    LIST_SOURCE_TYPE: ClassVar[set[str]] = {
        "table",
        "query",
        "sql",
        "sql-pass-through",
        "value-list",
        "table-fields",
    }

    @property
    def list_source_type(self) -> str | None:
        return self.get_attribute_string("form:list-source-type")

    @list_source_type.setter
    def list_source_type(self, list_source_type: str | None) -> None:
        if list_source_type is None:
            self.del_attribute("form:list-source-type")
            return
        if list_source_type not in self.LIST_SOURCE_TYPE:
            raise ValueError
        self.set_attribute("form:list-source-type", list_source_type)

LIST_SOURCE_TYPE class-attribute

LIST_SOURCE_TYPE: set[str] = {
    "table",
    "query",
    "sql",
    "sql-pass-through",
    "value-list",
    "table-fields",
}

list_source_type property writable

list_source_type: str | None

OfficeTargetFrameMixin

Bases: Element

Mixin for the “office:target-frame” attribute.

Usable with the following elements: “form:button”, “form:form” and “form:imag”.

Attributes:

Name Type Description
TARGET_FRAME set[str]
target_frame str | None
Source code in odfdo/form_controls_mixins.py
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
class OfficeTargetFrameMixin(Element):
    """Mixin for the "office:target-frame" attribute.

    Usable with the following elements: "form:button", "form:form" and
    "form:imag".
    """

    TARGET_FRAME: ClassVar[set[str]] = {"_blank", "_parent", "_self", "_top"}

    @property
    def target_frame(self) -> str | None:
        return self._get_attribute_str_default("office:target-frame", "_blank")

    @target_frame.setter
    def target_frame(self, target_frame: str | None) -> None:
        # target_frame can be any str (frame name)
        self._set_attribute_str_default("office:target-frame", target_frame, "_blank")

TARGET_FRAME class-attribute

TARGET_FRAME: set[str] = {
    "_blank",
    "_parent",
    "_self",
    "_top",
}

target_frame property writable

target_frame: str | None