Class based Views

REST Views

Fusionbox generic views.

class fusionbox.views.RestView(**kwargs)[source]

Inherit this base class to implement a REST view.

This view will handle:
  • authentication (throuh the auth method)
  • dispatching to the proper HTTP method function
  • returning a proper error status code.

It also implements a default response for the OPTIONS HTTP request method.

auth(*args, **kwargs)[source]

Hook for implementing custom authentication.

Raises NotImplementedError by default. Subclasses must overwrite this.

dispatch(*args, **kwargs)[source]

Authenticates the request and dispatches to the correct HTTP method function (GET, POST, PUT,...).

Translates exceptions into proper JSON serialized HTTP responses:
  • ValidationError: HTTP 409
  • Http404: HTTP 404
  • PermissionDenied: HTTP 403
  • ValueError: HTTP 400
options(request, *args, **kwargs)[source]

Implements a OPTIONS HTTP method function returning all allowed HTTP methods.

REST View Mixins

View classes to help facilitate the creation of REST APIs

class fusionbox.views.rest.JsonRequestMixin[source]

Adds a data method on the view instance. It returns the GET parameters if it is a GET request. It will return the python representation of the JSON sent with the request body.

data()[source]

Helper class for parsing JSON POST data into a Python object.

class fusionbox.views.rest.JsonResponseMixin[source]

Sets the response MIME type to application/json and serializes the context obj as a JSON string.

http_method_not_allowed(*args, **kwargs)[source]

Returns super after setting the Content-Type header to application/json

render_to_response(obj, **response_kwargs)[source]

Returns an HttpResponse object instance with Content-Type: application/json.

The response body will be the return value of self.serialize(obj)

serialize(obj)[source]

Returns a json serialized string object encoded using fusionbox.core.serializers.FusionboxJSONEncoder.