Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add read method for RefSkel #1193

Merged
merged 8 commits into from
Jul 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion src/viur/core/skeleton.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ def __getattr__(self, item: str):
# Load a @classmethod from the Skeleton class and bound this SkeletonInstance
elif item in {"fromDB", "toDB", "all", "unserialize", "serialize", "fromClient", "getCurrentSEOKeys",
"preProcessSerializedData", "preProcessBlobLocks", "postSavedHandler", "setBoneValue",
"delete", "postDeletedHandler", "refresh"}:
"delete", "postDeletedHandler", "refresh", "read"}:
return partial(getattr(self.skeletonCls, item), self)
# Load a @property from the Skeleton class
try:
Expand Down Expand Up @@ -1368,6 +1368,22 @@ def fromSkel(cls, kindName: str, *args: list[str]) -> t.Type[RefSkel]:
newClass.__boneMap__ = bone_map
return newClass

def read(self, key: t.Optional[db.Key | str | int] = None) -> SkeletonInstance:
"""
Read full skeleton instance referenced by the RefSkel from the database.

Can be used for reading the full Skeleton from a RefSkel.
The `key` parameter also allows to read another, given key from the related kind.

:raise ValueError: If the entry is no longer in the database.
"""
skel = skeletonByKind(self.kindName)()

if not skel.fromDB(key or self["key"]):
raise ValueError(f"""The key {key or self["key"]!r} seems to be gone""")

return skel


class SkelList(list):
"""
Expand Down
Loading