Source code for labapi.entry.entries.text
"""Text-based Entry Classes Module.
This module defines various classes for text-based entries within LabArchives,
including a base class for common text entry functionalities and specific
implementations for plain text, rich text, and header entries.
"""
from __future__ import annotations
from typing_extensions import override
from .base import Entry
[docs]
class PlainTextEntry(Entry[str], part_type="plain text entry"):
"""Represents a plain text entry on a LabArchives page.
This class is used for entries containing unformatted text.
It also serves as the base class for string-content entries, providing the
``content`` getter and setter.
"""
@property
@override
def content(self) -> str:
"""Return the entry text.
:returns: The content of the entry as a string.
"""
return self._data
@content.setter
@override
def content(self, value: str) -> None:
"""Set the entry text.
This operation updates the entry's content in LabArchives via an API call.
:param value: The new text content for the entry.
"""
if not isinstance(value, str):
raise TypeError(f"content must be a str, got {type(value).__name__}")
self._user.api_post("entries/update_entry", {"entry_data": value}, eid=self.id)
self._data = value
[docs]
class TextEntry(PlainTextEntry, part_type="text entry"):
"""Represents a rich text entry on a LabArchives page.
This class is used for entries containing formatted text, typically HTML.
"""