ripozo.dispatch.adapters package

Submodules

ripozo.dispatch.adapters.base module

class ripozo.dispatch.adapters.base.AdapterBase(resource, base_url='')[source]

Bases: object

The adapter base is responsible for specifying how a resource should be translated for the client. For example, you may want to specify a specific hypermedia protocol or format it in a manner that is specific to your client (though you should probably avoid that)

Parameters

formats (list) – A list of strings that indicate which Content-Types will match with this adapter. For example, you might include ‘application/vnd.siren+json’ in the formats for a SIREN adapter. This means that any request with that content type will be responded to in the appropriate manner. Any of the strings in the list will be considered the appropriate format for the adapter on which they are specified.

combine_base_url_with_resource_url(resource_url)[source]

Does exactly what it says it does. Uses join_url_parts with the self.base_url and resource_url argument together.

Parameters

resource_url (unicode) – The part to join with the self.base_url

Returns

The joined url

Return type

unicode

abstract property extra_headers

Headers that should be added to response. For example it might be the response-type etc…

Returns

A dictionary of the headers to return.

Return type

dict

classmethod format_exception(exc)[source]

Takes an exception and appropriately formats the response. By default it just returns a json dump of the status code and the exception message. Any exception that does not have a status_code attribute will have a status_code of 500.

Parameters

exc (Exception) – The exception to format.

Returns

A tuple containing: response body, format, http response code

Return type

tuple

formats = None
abstract property formatted_body

This property is the fully qualified and formatted response. For example, you might return a Hypermedia formatted response body such as the SIREN hypermedia protocol or HAL

Returns

The formatted response body.

Return type

unicode

property status_code
Returns

Returns the status code of the resource if it is available. If it is not it assumes a 200.

Return type

int

ripozo.dispatch.adapters.boring_json module

class ripozo.dispatch.adapters.boring_json.BoringJSONAdapter(resource, base_url='')[source]

Bases: ripozo.dispatch.adapters.base.AdapterBase

Just a plain old JSON dump of the properties. Nothing exciting.

Format:

<resource_name>: {

field1: “value” field2: “value” relationship: {

relationship_field: “value”

} list_relationship: [

{

relationship_field: “value”

relationship_field: “value”

}

]

}

property extra_headers
Returns

A dictionary of headers that should be included in the response

Return type

dict

formats = ['json', 'application/json']
property formatted_body
Returns

The formatted body that should be returned. It’s just a json.dumps of the properties and relationships

Return type

unicode

ripozo.viewsets.constructor module

class ripozo.viewsets.constructor.ResourceMetaClass[source]

Bases: type

A metaclass that is used for registering ResourceBase and its subclasses

Parameters
  • registered_resource_classes (dict) – A dictionary mapping the classes instantiated by this meta class to their base_urls

  • registered_names_map (dict) – A dictionary mapping the names of the classes to the actual instances of this meta class

registered_names_map = {}
registered_resource_classes = {}

ripozo.dispatch.adapters.hal module

class ripozo.dispatch.adapters.hal.HalAdapter(resource, base_url='')[source]

Bases: ripozo.dispatch.adapters.base.AdapterBase

An adapter that formats the response in the HAL format. A description of the HAL format can be found here: HAL Specification

property extra_headers
Returns

Just returns a single header for the Content-Type

Return type

dict

formats = ['hal', 'application/hal+json']
property formatted_body
Returns

The response body for the resource.

Return type

unicode

generate_relationship(relationship_list)[source]

Generates an appropriately formated embedded relationship in the HAL format.

Parameters

relationship (ripozo.viewsets.relationships.relationship.BaseRelationship) – The relationship that an embedded version is being created for.

Returns

If it is a ListRelationship it will return a list/collection of the embedded resources. Otherwise it returns a dictionary as specified by the HAL specification.

Return type

list|dict

ripozo.dispatch.adapters.siren module

class ripozo.dispatch.adapters.siren.SirenAdapter(resource, base_url='')[source]

Bases: ripozo.dispatch.adapters.base.AdapterBase

An adapter that formats the response in the SIREN format. A description of a SIREN format can be found here: SIREN specification

property extra_headers

The headers that should be appended to the response

Returns

a dictionary of the headers to be set on the response

Return type

dict

formats = ['siren', 'application/vnd.siren+json']
property formatted_body

Gets the formatted body of the response in unicode form. If self.status_code == 204 then this will return an empty string.

Returns

The siren formatted response body

Return type

unicode

generate_entity(resource, name, embedded)[source]

A generator that yields entities

generate_fields_for_endpoint_funct(endpoint_func)[source]

Returns the action’s fields attribute in a SIREN appropriate format.

Parameters

endpoint_func (apimethod) –

Returns

A dictionary of action fields

Return type

dict

get_entities()[source]

Gets a list of related entities in an appropriate SIREN format

Returns

A list of entities

Return type

list

Module contents