djblets.webapi.responses¶
- class WebAPIResponse(request, obj={}, stat='ok', api_format=None, status=200, headers={}, encoders=[], encoder_kwargs={}, mimetype=None, supported_mimetypes=None)[source]¶
An API response, formatted for the desired file format.
- property content[source]¶
Returns the API response content in the appropriate format.
This is an overridden version of HttpResponse._get_content that generates the resulting content when requested, rather than generating it up-front in the constructor. This is used so that the @webapi decorator can set the appropriate API format before the content is generated, but after the response is created.
- class WebAPIResponsePaginated(request, queryset=None, results_key='results', prev_key='prev', next_key='next', total_results_key='total_results', start_param='start', max_results_param='max-results', default_start=0, default_max_results=25, max_results_cap=200, serialize_object_func=None, extra_data={}, *args, **kwargs)[source]¶
A response containing a list of results with pagination.
This accepts the following parameters to the URL:
start - The index of the first item (0-based index).
max-results - The maximum number of results to return in the request.
Subclasses can override much of the pagination behavior of this function. While the default behavior operates on a queryset and works on indexes within that queryset, subclasses can override this to work on any data and paginate in any way they see fit.
- normalize_start(start)[source]¶
Normalizes the start value.
By default, this ensures it’s an integer no less than 0. Subclasses can override this behavior.
- get_total_results()[source]¶
Returns the total number of results across all pages.
Subclasses can return None to prevent this field from showing up in the payload.