djblets.webapi.responses¶
-
class
WebAPIResponse
(request, obj={}, stat=u'ok', api_format=None, status=200, headers={}, encoders=[], encoder_kwargs={}, mimetype=None, supported_mimetypes=None)[source]¶ Bases:
django.http.response.HttpResponse
An API response, formatted for the desired file format.
-
__init__
(request, obj={}, stat=u'ok', api_format=None, status=200, headers={}, encoders=[], encoder_kwargs={}, mimetype=None, supported_mimetypes=None)[source]¶ x.__init__(…) initializes x; see help(type(x)) for signature
-
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=u'results', prev_key=u'prev', next_key=u'next', total_results_key=u'total_results', start_param=u'start', max_results_param=u'max-results', default_start=0, default_max_results=25, max_results_cap=200, serialize_object_func=None, extra_data={}, *args, **kwargs)[source]¶ Bases:
djblets.webapi.responses.WebAPIResponse
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.
-
__init__
(request, queryset=None, results_key=u'results', prev_key=u'prev', next_key=u'next', total_results_key=u'total_results', start_param=u'start', max_results_param=u'max-results', default_start=0, default_max_results=25, max_results_cap=200, serialize_object_func=None, extra_data={}, *args, **kwargs)[source]¶ x.__init__(…) initializes x; see help(type(x)) for signature
-
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.
-
class
WebAPIResponseError
(request, err, extra_params={}, headers={}, *args, **kwargs)[source]¶ Bases:
djblets.webapi.responses.WebAPIResponse
A general API error response.
This contains an error code and a human-readable message. Additional data can be provided through
extra_params
andheaders
.
-
class
WebAPIResponseFormError
(request, form, *args, **kwargs)[source]¶ Bases:
djblets.webapi.responses.WebAPIResponseError
An error response designed to return all errors from a form.