everest.entities.base

Entity and aggregate base classes.

class everest.entities.base.Aggregate(entity_class, session_factory)[source]

Bases: object

Abstract base class for all aggregates.

An aggregate is an accessor for a set of entities of the same type which are held in some repository.

The wrapped entity set may be a “root” set of all entities in the repository or a “relation” set defined by a relationship to entities of some other type.

Supports filtering, sorting, slicing, counting, iteration as well as retrieving, adding and removing entities.

__init__(entity_class, session_factory)[source]

Constructor:

Parameters:
  • entity_class (a class implementing everest.entities.interfaces.IEntity) – the entity class (type) of the entities in this aggregate.
  • session – Session object.
__weakref__

list of weak references to the object (if defined)

add(entity)[source]

Adds an entity to the aggregate.

If the entity has an ID, it must be unique within the aggregate.

Parameters:entity (object implementing everest.entities.interfaces.IEntity) – entity (domain object) to add
Raises ValueError:
 if an entity with the same ID exists
clone()[source]

Returns a clone of this aggregate.

count()[source]

Returns the total number of entities in the underlying aggregate. If specified, filter specs are applied. A specified slice key is ignored.

Returns:number of aggregate members (int)
classmethod create(entity_class, session_factory)[source]

Factory class method to create a new aggregate.

entity_class = None

Entity class (type) of the entities in this aggregate.

get_by_id(id_key)[source]

Returns an entity by ID from the underlying aggregate or None if the entity is not found.

Note :if a filter is set which matches the requested entity, it will not be found.
Parameters:id_key (int or str) – ID value to look up
Raises :everest.exceptions.DuplicateException if more than one entity is found for the given ID value.
Returns:specified entity or None

Returns a single entity from the underlying aggregate by ID.

get_by_slug(slug)[source]

Returns an entity by slug or None if the entity is not found.

Parameters:slug (str) – slug value to look up
Raises :everest.exceptions.DuplicateException if more than one entity is found for the given ID value.
Returns:entity or None
iterator()[source]

Returns an iterator for the entities contained in the underlying aggregate.

If specified, filter, order, and slice settings are applied.

Returns:an iterator for the aggregate entities
remove(entity)[source]

Removes an entity from the aggregate.

Parameters:entity (object implementing everest.entities.interfaces.IEntity) – entity (domain object) to remove
Raises ValueError:
 entity was not found
set_relationship(relationship)[source]

Sets a relationship for this aggregate.

Parameters:relationship – instance of thelma.relationsip.Relationship.
class everest.entities.base.Entity(id=None)[source]

Bases: object

Abstract base class for all model entities.

All entities have an ID which is used as the default value for equality comparison. The object may be initialized without an ID.

__weakref__

list of weak references to the object (if defined)

slug[source]

Returns a human-readable and URL-compatible string that is unique within all siblings of this entity.

Project Versions

Previous topic

everest.entities.attributes

Next topic

everest.entities.interfaces

This Page