Jump to >

djblets.webapi.decorators

copy_webapi_decorator_data(from_func, to_func)[source]

Copies and merges data from one decorated function to another.

This will copy over the standard function information (name, docs, and dictionary data), but will also handle intelligently merging together data set by webapi decorators, such as the list of possible errors.

webapi_decorator(decorator)[source]

Decorator for simple webapi decorators.

This is meant to be used for other webapi decorators in order to intelligently preserve information, like the possible response errors. It handles merging lists of errors and other information instead of overwriting one list with another, as simple_decorator would do.

webapi(f)[source]

Indicates that a view is a Web API handler.

webapi_response_errors(*errors)[source]

Specifies the type of errors that the response may return.

This can be used for generating documentation or schemas that cover the possible error responses of methods on a resource.

webapi_login_required(f)[source]

Checks that the user is logged in before invoking the view. If the user is not logged in, a NOT_LOGGED_IN error (HTTP 401 Unauthorized) is returned.

webapi_permission_required(perm)[source]

Checks that the user is logged in and has the appropriate permissions to access this view. A PERMISSION_DENIED error is returned if the user does not have the proper permissions.

webapi_request_fields(required={}, optional={}, allow_unknown=False)[source]

Validates incoming fields for a request.

This is a helpful decorator for ensuring that the fields in the request match what the caller expects.

The parsed fields will be passed in as keyword arguments to the decorated function. There will also be an additional keyword argument, parsed_request_fields, that is a dictionary of all the parsed request fields.

If any field is set in the request that is not in either required or optional and allow_unknown is True, the response will be an INVALID_FORM_DATA error. The exceptions are the special fields method and callback.

If any field in required is not passed in the request, these will also be listed in the INVALID_FORM_DATA response.

The required and optional parameters are dictionaries mapping field name to an info dictionary, which contains the following keys:

  • type - The data type for the field.
  • description - A description of the field.

For example:

@webapi_request_fields(required={
    'name': {
        'type': str,
        'description': 'The name of the object',
    }
})