ripozo.managers package

Submodules

ripozo.managers.base module

class ripozo.managers.base.BaseManager[source]

Bases: object

The BaseManager implements some common methods that are valuable across all databases as well as expose an interface that must be implemented by any specific implementation. This needs to be extended in order to implement a new database type. This should handle all direct interactions with a database or ORM. The extended classes are injected into viewsets in order to specify how to get the data from the database.

Parameters:
  • pagination_pk_query_arg (unicode) – The name of the query parameter that specifies the page or pk for the next set page to return when paginating over a list
  • pagination_count_query_arg (unicode) – The name of the query parameter that specifies the maximum number of results to return in a list retrieval
  • pagination_next (unicode) – The meta parameter to return that specifies the next query parameters
  • paginate_by (int) – The number of results to return by default. This gets overridden by pagination_count_query_arg
  • order_by (list) – A list of the fields to order the results by. This may be restricted in certain databases
  • fields (list) – A list of the fields that are able to be manipulated or retrieved by the manager
  • model (type) – The model that is being managed. This is the individual model that is set by the user. For any type of base class this should be None. However, it is required for actual implementations
arg_parser = None
create(values, *args, **kwargs)[source]

Create a model with the values according to the values dictionary

Parameters:
  • values (dict) – A dictionary of values to create the model according to
  • args (tuple) – Extra arguments
  • kwargs (dict) – Extra keyword arguments
Returns:

The dictionary of arguments that should be returned by the serializer

Return type:

dict

delete(lookup_keys, *args, **kwargs)[source]

Deletes the model found with the lookup keys

Parameters:
  • lookup_keys (dict) – The keys with which to find the model to delete
  • args (tuple) – Extra arguments
  • kwargs (dict) – Extra keyword arguments
Returns:

nothing.

Return type:

NoneType

dot_field_list_to_dict(fields=None)[source]

Converts a list of dot delimited fields (and related fields) and turns it into a dictionary for example, it would transform

>>> dot_field_list_to_dict(['id', 'value', 'related.id', 'related.related_value'])
{
    'id': None,
    'value': None,
    'related': {
        'id': None,
        'related_value': None
    }
}
Parameters:fields (list) –
Returns:A dictionary of the fields layered as to indicate relationships.
Return type:dict
field_validators = []
fields = []
get_field_type(name)[source]

Returns the BaseField instance (or subclass) instance that corresponds to the named attribute on the model. For example, if you the column “name” on the model for this manager is a String column, then this should return an instance of StringField with the appropriate requirements.

Parameters:name (unicode) – The name of the field on the model for which you are getting the field name
Returns:The BaseField class (or subclass) instance to handle the field specified by the name
Return type:ripozo.viewsets.fields.base.BaseField
get_pagination_count(filters)[source]

Get the pagination count from the args

Parameters:filters (dict) – All of the args
Returns:tuple of (pagination_count, updated_filters
Return type:tuple
get_pagination_pks(filters)[source]

Get the pagination pks from the args

Parameters:filters (dict) – All of the args
Returns:tuple of (pagination_pks, updated_filters
Return type:tuple
list_fields = []
model = None
order_by = None
paginate_by = 10000
pagination_count_query_arg = u'count'
pagination_next = u'next'
pagination_pk_query_arg = u'pagination_pk'
queryset

Gets the list of models that are valid to operate on

Returns:A list of models
Return type:list
retrieve(lookup_keys, *args, **kwargs)[source]

Retrieve a single model and nothing more as a python dictionary

Parameters:
  • lookup_keys (dict) – The lookup keys for the model and the associated values
  • args (tuple) – Extra arguments
  • kwargs (dict) – Extra keyword arguments
Returns:

The dictionary of arguments that should be returned by the serializer

Returns:

A tuple with the first object being a dictionary of key value pairs according to the fields list and

the second object is the meta data (such as the next url for a paginated list) :rtype: tuple

retrieve_list(filters, *args, **kwargs)[source]

Retrieves a list of dictionaries containing the fields for the associated model

Parameters:
  • lookup_keys (dict) – The lookup keys for the model and the associated values
  • args (tuple) – Extra arguments
  • kwargs (dict) – Extra keyword arguments
Returns:

The dictionary of arguments that should be returned by the serializer

Returns:

A a list of dictionaries of key value pairs according to the fields list

Return type:

list

update(lookup_keys, updates, *args, **kwargs)[source]

Updates the model found with the lookup keys according to the updates dictionary where the keys are the fields to update and the values are the new values for the field

Parameters:
  • lookup_keys (dict) – The keys to find the object that is to be updated
  • updates (dict) – The fields to update and their associated new update values
  • args (tuple) – Extra arguments
  • kwargs (dict) – Extra keyword arguments
Returns:

A dictionary of the full updated model according to the fields class attribute

Return type:

dict

Module contents