Jump to >

This documentation covers Djblets 2.0. You can see the latest Djblets documentation or all other versions.

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.

supported_mimetypes = [u'application/json', u'application/xml'][source]
__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.

has_prev()[source]

Returns whether there’s a previous set of results.

has_next()[source]

Returns whether there’s a next set of results.

get_prev_index()[source]

Returns the previous index to use for ?start=

get_next_index()[source]

Returns the next index to use for ?start=

get_results()[source]

Returns the results for this page.

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.

Returns all links used in the payload.

By default, this only includes pagination links. Subclasses can provide additional links.

build_pagination_url(full_path, start, max_results, query_parameters)[source]

Builds a URL to go to the previous or next set of results.

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 and headers.

__init__(request, err, extra_params={}, headers={}, *args, **kwargs)[source]

x.__init__(…) initializes x; see help(type(x)) for signature

class WebAPIResponseFormError(request, form, *args, **kwargs)[source]

Bases: djblets.webapi.responses.WebAPIResponseError

An error response designed to return all errors from a form.

__init__(request, form, *args, **kwargs)[source]

x.__init__(…) initializes x; see help(type(x)) for signature