Code documentation

exception atomic_operations.exceptions.InvalidPrimaryDataType(idx, data_type: str)
exception atomic_operations.exceptions.JsonApiParseError(id, detail, pointer, status=400, code=None)
exception atomic_operations.exceptions.MissingPrimaryData(idx: int)
exception atomic_operations.exceptions.UnprocessableEntity(detail=None, code=None)
default_code = 'unprocessable_entity'
default_detail = 'Unprocessable entity.'
status_code = 422

Parsers

class atomic_operations.parsers.AtomicOperationParser

Similar to JSONRenderer, the JSONParser you may override the following methods if you need highly custom parsing control.

A JSON:API client will send a payload that looks like this:

{
    "atomic:operations": [{
            "op": "add",
            "data": {
                "type": "articles",
                "attributes": {
                    "title": "JSON API paints my bikeshed!"
                }
            }
        }]
}

We extract the attributes so that DRF serializers can work as normal.

check_add_operation(idx, data)
check_operation(idx: int, operation: Dict)
check_relation_update(idx, operation)
check_remove_operation(idx, ref)
check_resource_identifier_object(idx: int, resource_identifier_object: Dict, operation_code: str)
check_root(result)
check_update_operation(idx, operation)
media_type = 'application/vnd.api+json;ext="https://jsonapi.org/ext/atomic'
parse_data(result, parser_context)

Formats the output of calling JSONParser to match the JSON:API specification and returns the result.

parse_id_and_type(resource_identifier_object)
parse_operation(resource_identifier_object, result)
renderer_class

alias of JSONRenderer

Renderers

class atomic_operations.renderers.AtomicResultRenderer

The JSONRenderer exposes a number of methods that you may override if you need highly custom rendering control.

Render a JSON response per the JSON:API spec:

{
  "atomic:results": [{
    "data": {
      "links": {
        "self": "http://example.com/blogPosts/13"
      },
      "type": "articles",
      "id": "13",
      "attributes": {
        "title": "JSON API paints my bikeshed!"
      }
    }
  }]
}
check_error(operation_result_data, accepted_media_type, renderer_context)
format = 'vnd.api+json;ext="https://jsonapi.org/ext/atomic'
media_type = 'application/vnd.api+json;ext="https://jsonapi.org/ext/atomic'
render(data: List[OrderedDict], accepted_media_type=None, renderer_context=None)

Render data into JSON, returning a bytestring.

class atomic_operations.views.AtomicOperationView(**kwargs)

View which handles JSON:API Atomic Operations extension https://jsonapi.org/ext/atomic/

get_serializer(idx, operation_code, resource_type, *args, **kwargs)

Return the serializer instance that should be used for validating and deserializing input, and for serializing output.

get_serializer_class(operation_code: str, resource_type: str)
get_serializer_classes() Dict
get_serializer_context()

Extra context provided to the serializer class.

handle_bulk(serializer, current_operation_code, bulk_operation_data)
handle_sequential(serializer, operation_code)
http_method_names = ['post']
parser_classes = [<class 'atomic_operations.parsers.AtomicOperationParser'>]
perform_bulk_create(bulk_operation_data)
perform_bulk_delete(bulk_operation_data)
perform_operations(parsed_operations: List[Dict])
post(request, *args, **kwargs)
renderer_classes = [<class 'atomic_operations.renderers.AtomicResultRenderer'>]
response_data: List[Dict] = []
sequential = True
serializer_classes: Dict = {}