rest_flex_fields2.utils
Utility helpers for rest_flex_fields2.
Provides request-inspection functions (is_expanded, is_included) and the split_levels helper that partitions dot-notation field lists into current-level and next-level fragments.
Functions
|
Return whether field is requested for expansion. |
|
Return whether field should be included in the response. |
|
Split a dot-notation field list into current-level and next-level parts. |
Module Contents
- rest_flex_fields2.utils.is_expanded(request, field)[source]
Return whether field is requested for expansion.
Inspects the
expandquery parameter on request. ReturnsTruewhen field appears in the comma-separated expand list, or when a wildcard value (e.g.*or~all) is present.- Parameters:
field (str)
- Return type:
bool
- rest_flex_fields2.utils.is_included(request, field)[source]
Return whether field should be included in the response.
Returns
Falsewhen thefieldssparse-fieldset parameter is present and field is not listed, or when theomitparameter is present and field is listed. ReturnsTrueotherwise.- Parameters:
field (str)
- Return type:
bool
- rest_flex_fields2.utils.split_levels(fields)[source]
Split a dot-notation field list into current-level and next-level parts.
Given an iterable such as
['a', 'a.b', 'a.d', 'c'], returns a tuple(first_level, next_level)wherefirst_levelis the deduplicated list of top-level names (e.g.['a', 'c']) andnext_levelis a dict mapping each name to its remaining path fragments (e.g.{'a': ['b', 'd']}). A plain string is treated as a comma-separated field list.- Parameters:
fields (str | collections.abc.Iterable[str])
- Return type:
tuple[list[str], dict[str, list[str]]]