mirror of
https://github.com/tiqi-group/pydase.git
synced 2025-04-21 16:50:02 +02:00
adds "no_frontend" decorator for emitting frontend rendering of method
The method serialization now contains a "frontend_render" key with boolean value.
This commit is contained in:
parent
ccc53c395e
commit
3c2f425dee
@ -29,6 +29,23 @@ class KeywordArgumentError(Exception):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
# TODO: This decorator might be used on objects other than functions
|
||||||
|
def no_frontend(func: Callable[..., Any]) -> Callable[..., Any]:
|
||||||
|
"""Decorator to mark a DataService method as excluded from frontend rendering."""
|
||||||
|
|
||||||
|
func._hide_from_frontend = True # type: ignore
|
||||||
|
return func
|
||||||
|
|
||||||
|
|
||||||
|
def render_in_frontend(func: Callable[..., Any]) -> bool:
|
||||||
|
"""Determines if the method is not decorated with the `@no_frontend` decorator."""
|
||||||
|
|
||||||
|
try:
|
||||||
|
return func._hide_from_frontend # type: ignore
|
||||||
|
except AttributeError:
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
class Serializer:
|
class Serializer:
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def serialize_object(obj: Any) -> dict[str, Any]:
|
def serialize_object(obj: Any) -> dict[str, Any]:
|
||||||
@ -197,6 +214,7 @@ class Serializer:
|
|||||||
"doc": doc,
|
"doc": doc,
|
||||||
"async": inspect.iscoroutinefunction(obj),
|
"async": inspect.iscoroutinefunction(obj),
|
||||||
"parameters": parameters,
|
"parameters": parameters,
|
||||||
|
"frontend_render": render_in_frontend(obj),
|
||||||
}
|
}
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
Loading…
x
Reference in New Issue
Block a user