-
Notifications
You must be signed in to change notification settings - Fork 14
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: Evaluate x-viur-bonelist
on default viewSkel()
(light-version)
#1415
base: main
Are you sure you want to change the base?
Conversation
This is a lighter version of viur-framework#1384, integrating the feature only for `Singleton` and `List`.
@@ -110,6 +112,46 @@ def baseSkel(self, *args, **kwargs) -> SkeletonInstance: | |||
""" | |||
return self._resolveSkelCls(*args, **kwargs)() | |||
|
|||
def skel( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've in a project already a custom quick & dirty solution, based on #1384.
def skel_from_header(
self,
*args,
bones_exclude: tuple[str, ...] | t.List[str] = (),
**kwargs,
) -> SkeletonInstance:
X_VIUR_BONELIST: t.Final[str] = "X-VIUR-BONELIST"
skel_cls = self._resolveSkelCls(**kwargs)
bones = set()
if bonelist := current.request.get().request.headers.get(X_VIUR_BONELIST):
if "*" not in skel_cls.subSkels: # a named star-subskel "*"" must exist!
raise errors.BadRequest(f"Use of {X_VIUR_BONELIST!r} requires for a star-subskel")
bones |= {bone.strip() for bone in bonelist.split(",")}
bones.difference_update(bones_exclude)
if bones: # Return a subskel?
log.debug(f"{current.request.get().response.vary=}")
current.request.get().response.vary = (X_VIUR_BONELIST, *(current.request.get().response.vary or ()))
# When coming from outside of a request, "*" is always involved.
return skel_cls.subskel("*", bones=bones)
elif bones_exclude: # Return full skel, without generally excluded bones
bones.update(skel_cls.__boneMap__.keys())
bones.difference_update(bones_exclude)
return skel_cls(bones=bones)
# Otherwise, return full skeleton
return skel_cls()
Can you please integrate the bones_exclude
param and the vary header in your method too?
@@ -110,6 +112,46 @@ def baseSkel(self, *args, **kwargs) -> SkeletonInstance: | |||
""" | |||
return self._resolveSkelCls(*args, **kwargs)() | |||
|
|||
def skel( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why don't you implement this directly in baseSkel
? Now you have to customize every call (baseSkel()
--> skel()
). If you would implement this in baseSkel
, all calls could remain the same and you would be more backwards compatible.
With yet another *skel
method, it only gets more complicated.
This is a lighter version of #1384, integrating the feature only for
Singleton
andList
.