Package pyperry :: Package middlewares :: Module model_bridge :: Class ModelBridge
[frames] | no frames]

Class ModelBridge

source code

object --+
         |
        ModelBridge

The ModelBridge class is positioned between the processors and middlewares in the adapter's request/response call stack. Before the response from an adapter call reaches the ModelBridge, the middlewares can only reliable work with the raw response data. After the ModelBridge handles the response, the processors that follow can now operate on model instances (subclasses of pyperry.Base) instead of the raw response data.

On adapter reads, the ModelBridge takes the list of records returned by the adapter call and creates a model instance of the appropriate type for each record in the list.

On adapter writes and deletes, the ModelBridge class updates the state of the model instance being saved or deleted to reflect the data stored in the Response object returned by the adapter call. This includes things like updating a model's saved and new_record attributes in addition to putting error messages on the model if the adapter received an error response. Additionally, the ModelBridge will refresh all of the model's data attributes (specified by calling pyperry.Base.attributes(...)) after a successful write if a read adapter is configured for the model.

Instance Methods
 
__init__(self, next, options={})
x.__init__(...) initializes x; see x.__class__.__doc__ for signature
source code
 
__call__(self, **kwargs) source code
 
handle_read(self, records, **kwargs)
Create perry.Base instances from the raw records dictionaries.
source code
 
handle_write(self, response, **kwargs)
Updates a model after a save.
source code
 
handle_write_success(self, response, model)
Updates the model's state attributes and retrieves a fresh version of the data attributes if a read adapter is configured.
source code
 
handle_write_failure(self, response, model)
Updates the model instance when a save fails
source code
 
handle_delete(self, response, **kwargs)
Updates the model instance after a delete
source code
 
add_errors(self, response, model, default_message)
Copies the response errors to the model or uses a default error message if the response errors are empty.
source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Properties

Inherited from object: __class__

Method Details

__init__(self, next, options={})
(Constructor)

source code 

x.__init__(...) initializes x; see x.__class__.__doc__ for signature

Overrides: object.__init__
(inherited documentation)