ripozo.viewsets.relationships package¶
Submodules¶
ripozo.viewsets.relationships.list_relationship module¶
-
class
ripozo.viewsets.relationships.list_relationship.
ListRelationship
(name, property_map=None, relation=None, embedded=False, required=False)[source]¶ Bases:
ripozo.viewsets.relationships.relationship.Relationship
Special case for a list of relationships.
-
construct_resource
(properties, query_args=None)[source]¶ Takes a list of properties and returns a generator that yields Resource instances. These related ResourceBase subclass will be asked to construct an instance with the keyword argument properties equal to each item in the list of properties provided to this function.
- Parameters
properties (dict) – A dictionary of the properties on the parent model. The list_name provided in the construction of an instance of this class is used to find the list that will be iterated over to generate the resources.
- Returns
A generator that yields the relationships.
- Return type
types.GeneratorType
-
remove_child_resource_properties
(properties)[source]¶ Removes the item from the properties dict with the key that matches this instance’s list_name attribute. It copies the properties and pops the property from the copy before returning it.
- Parameters
properties (dict) – The properties with the list_name key and value to be removed.
- Returns
The updated properties dict. This is actually a copy of the original to prevent side effects.
- Return type
dict
-
ripozo.viewsets.relationships.relationship module¶
-
class
ripozo.viewsets.relationships.relationship.
Relationship
(name, property_map=None, relation=None, embedded=False, required=False)[source]¶ Bases:
object
Defines a relationship on a resource. This allows you to create related resources and construct them appropriately. As usual, the actual response is created by an adapter which must determine whether to return the whole resource, a link, etc…
-
construct_resource
(properties, query_args=None)[source]¶ Takes the properties from the parent and and maps them to the named properties for the parent resource to its relationships
- Parameters
properties (dict) –
- Returns
An instance of a self.relation class that corresponds to this related resource
- Return type
rest.viewsets.resource_base.ResourceBase
-
property
relation
¶ The ResourceBase subclass that describes the related object If no _relation property is available on the instance it returns None. Raises a key error when the relation keyword argument passed on construction is not available in the self._resource_meta_class.registered_names_map dictionary (By default the self._resource_meta_class is the ResourceMetaClass).
- Returns
The ResourceBase subclass that describes the related resource
- Return type
type
- Raises
KeyError
-
remove_child_resource_properties
(properties)[source]¶ Removes the properties that are supposed to be on the child resource and not on the parent resource. It copies the properties argument before it removes the copied values. It does not have side effects in other words.
- Parameters
properties (dict) – The properties that are in the related resource map that should not be in the parent resource.
- Returns
a dictionary of the updated properties
- Return type
dict
-