Common utility functions

exception vng_api_common.utils.NotAViewSet
vng_api_common.utils.get_resource_for_path(path: str) Model

Retrieve the API instance belonging to a (detail) path.

vng_api_common.utils.get_resources_for_paths(paths: List[str]) Optional[QuerySet]

Retrieve API instances belonging to a list of (detail) paths.

This is the bulk version of vng_api_common.utils.get_resource_for_path(), which doesn’t scale well when a lot of paths are involved. This replaces many queries with a single bulk query.


This means that all the resource paths must point to the same resource, as the viewset will only be fetched once from the first item and used to retrieve all the resources.

This function compares the number of resolved instances vs the number of input paths, and if that is not equal, there’s something off and a RuntimeError is raised.

vng_api_common.utils.get_uuid_from_path(path: str) str

Get the last path of path


Return the viewset’s general summary.

This will extract the paragraphs between the first line and the first operation description.

Example docstring:

Some operation description here that will not be included.

This text will be included below the tag.

This text will also be included.

create: First operation in the docstring which will not be included.


view_cls (type) – the view class to extra the docstring from.

vng_api_common.utils.get_viewset_for_path(path: str, method='GET') ViewSet

Look up which viewset matches a path.

vng_api_common.utils.lookup_kwargs_to_filters(lookup_kwargs: dict, kwargs: dict) dict

Using the lookup_kwargs map and the view kwargs, construct the queryset filter dict.

vng_api_common.utils.underscore_to_camel(input_: Union[str, int]) str

Convert a string from under_score to camelCase.