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_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
oroptional
andallow_unknown
is True, the response will be an INVALID_FORM_DATA error. The exceptions are the special fieldsmethod
andcallback
.If any field in
required
is not passed in the request, these will also be listed in the INVALID_FORM_DATA response.The
required
andoptional
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:
from djblets.webapi.decorators import webapi_request_fields from djblets.webapi.fields import StringFieldType @webapi_request_fields(required={ 'name': { 'type': StringFieldType, 'description': 'The name of the object', } })