magpie.api.management.group.group_formats¶
Functions¶
|
Evaluates the specified |
|
Obtains the JSON formatted Group definition according to field selection flags. |
Module Contents¶
- magpie.api.management.group.group_formats.evaluate_call(call: Callable[[], Any], fallback: Callable[[], None] | None = None, http_error: Type[pyramid.httpexceptions.HTTPError] = HTTPInternalServerError, http_kwargs: magpie.typedefs.ParamsType | None = None, msg_on_fail: magpie.typedefs.Str = '', content: magpie.typedefs.JSON | None = None, content_type: magpie.typedefs.Str = CONTENT_TYPE_JSON, metadata: magpie.typedefs.JSON | None = None) Any[source]¶
Evaluates the specified
callwith a wrapped HTTP exception handling. On failure, tries to call.fallbackif specified, and finally raises the specifiedhttp_error.Any potential error generated by
fallbackorhttp_errorthemselves are treated asHTTPInternalServerError.Exceptions are generated using the standard output method formatted based on specified
content_type.- Example:
normal call:
try: res = func(args) except Exception as exc: fb_func() raise HTTPExcept(exc.message)
wrapped call:
res = evaluate_call(lambda: func(args), fallback=lambda: fb_func(), http_error=HTTPExcept, **kwargs)
- Parameters:
call – function to call, MUST be specified as lambda: <function_call>
fallback – function to call (if any) when call failed, MUST be lambda: <function_call>
http_error – alternative exception to raise on call failure
http_kwargs – additional keyword arguments to pass to http_error if called in case of HTTP exception
msg_on_fail – message details to return in HTTP exception if call failed
content – json formatted additional content to provide in case of exception
content_type – format in which to return the exception (one of magpie.common.SUPPORTED_ACCEPT_TYPES)
metadata – request metadata to add to the response body. (see:
magpie.api.requests.get_request_info())
- Raises:
http_error – on call failure
HTTPInternalServerError – on fallback failure
- Returns:
whichever return value call might have if no exception occurred
- magpie.api.management.group.group_formats.format_group(group: magpie.models.Group, basic_info: bool = False, public_info: bool = False, dotted: bool = False, db_session: sqlalchemy.orm.session.Session | None = None) magpie.typedefs.JSON[source]¶
Obtains the JSON formatted Group definition according to field selection flags.
- Parameters:
group – Group for which to provide details.
basic_info – If
True, return only sufficient details to identify the group (useful for routes that refer to a group, but that are not requesting it specifically), or return full details (for routes that specifically request its information, e.g.:GET /groups/{grp}).public_info – Indicate if the returned details are intended for public information (
True) or admin-only (False). Only higher level users should be provided additional details to avoid leaking potentially sensitive parameters.dotted – Employ a dot (
.) instead of underscore (_) to separate Group from its basic information.db_session – Database connection to retrieve additional details (required when
public_info=False).