reports: Add BaseODS.set_custom_property() method.
This commit is contained in:
parent
59b088b573
commit
04be991e19
1 changed files with 31 additions and 0 deletions
|
@ -1052,6 +1052,37 @@ class BaseODS(BaseSpreadsheet[RT, ST], metaclass=abc.ABCMeta):
|
||||||
|
|
||||||
### Properties
|
### Properties
|
||||||
|
|
||||||
|
def set_custom_property(self,
|
||||||
|
name: str,
|
||||||
|
value: Any,
|
||||||
|
valuetype: Optional[str]=None,
|
||||||
|
) -> odf.meta.UserDefined:
|
||||||
|
if valuetype is None:
|
||||||
|
if isinstance(value, bool):
|
||||||
|
valuetype = 'boolean'
|
||||||
|
elif isinstance(value, (datetime.date, datetime.datetime)):
|
||||||
|
valuetype = 'date'
|
||||||
|
elif isinstance(value, (int, float, Decimal)):
|
||||||
|
valuetype = 'float'
|
||||||
|
if not isinstance(value, str):
|
||||||
|
if valuetype == 'boolean':
|
||||||
|
value = 'true' if value else 'false'
|
||||||
|
elif valuetype == 'date':
|
||||||
|
value = value.isoformat()
|
||||||
|
else:
|
||||||
|
value = str(value)
|
||||||
|
retval = self.ensure_child(self.document.meta, odf.meta.UserDefined, name=name)
|
||||||
|
if valuetype is None:
|
||||||
|
try:
|
||||||
|
retval.removeAttribute('valuetype')
|
||||||
|
except KeyError:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
retval.setAttribute('valuetype', valuetype)
|
||||||
|
retval.childNodes.clear()
|
||||||
|
retval.addText(value)
|
||||||
|
return retval
|
||||||
|
|
||||||
def set_properties(self, *,
|
def set_properties(self, *,
|
||||||
created: Optional[datetime.datetime]=None,
|
created: Optional[datetime.datetime]=None,
|
||||||
generator: str='conservancy_beancount',
|
generator: str='conservancy_beancount',
|
||||||
|
|
Loading…
Reference in a new issue