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: RelationalBone add getDefaultValue #1172

Draft
wants to merge 5 commits into
base: develop
Choose a base branch
from
Draft
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
31 changes: 31 additions & 0 deletions src/viur/core/bones/relational.py
Original file line number Diff line number Diff line change
Expand Up @@ -1244,6 +1244,37 @@
elif isinstance(value, list):
return self._hashValueForUniquePropertyIndex([x["dest"]["key"] for x in value])

def getDefaultValue(self, skeletonInstance):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about multilang?

def get_default_value_intern(value):
print(f"in get_default_value_intern ==")
if callable(value):
a= value(skeletonInstance, self)

Check failure on line 1251 in src/viur/core/bones/relational.py

View workflow job for this annotation

GitHub Actions / linter (3.12)

E225: missing whitespace around operator
print(a)
return a
return value

if callable(self.defaultValue):
key = self.defaultValue(skeletonInstance, self)
elif isinstance(self.defaultValue, list):
key = self.defaultValue
elif isinstance(self.defaultValue, dict):
data= {k: self.createRelSkelFromKey(get_default_value_intern(v)) for k, v in self.defaultValue.items()}

Check failure on line 1261 in src/viur/core/bones/relational.py

View workflow job for this annotation

GitHub Actions / linter (3.12)

E225: missing whitespace around operator
#print(data)

Check failure on line 1262 in src/viur/core/bones/relational.py

View workflow job for this annotation

GitHub Actions / linter (3.12)

E265: block comment should start with '# '
return data
else:
key = self.defaultValue
if not key:
return None
if self.multiple:
if isinstance(key, list):
return [self.createRelSkelFromKey(k) for k in key]
else:
return [self.createRelSkelFromKey(key)]
else:
if isinstance(key, list):
key = key[0]
return self.createRelSkelFromKey(key)

def structure(self) -> dict:
return super().structure() | {
"type": f"{self.type}.{self.kind}",
Expand Down
Loading