Entity module

Quick Start

For a quick start and a high level description of the usage of this module, refer to Creating your Entity.

Module Documentation

Base entity for modeling of API’s entities

class nova_api.entity.Entity(id_: str = <factory>, creation_datetime: datetime.datetime = <factory>, last_modified_datetime: datetime.datetime = <factory>)[source]

Base Entity implementation

This class is the base implementation of the entity for modeling API resources. The fields included in this class will be inherited for all subclasses.

Examples

@dataclass
class Person(Entity):
    name: str = None
    age: int = None
    birthday: date = None
__iter__()[source]

Iteration through the Entity receiving the tuple (field_name, field_value_serialized)

Iterates through the fields in the entity and yields a tuple with the field_name and the serialized field_value. For fields that are instances of Entities, the key will have _id_ appended and the value will be the id_, as stated in _serialize_field.

Return key, value:
 The tuple with the field_name and field_value
__post_init__()[source]

Post processing of fields

Post init goes through the parameters passed to init and makes some validations. Fields that are subclasses of Entity will be instantiated (but only with id_ set). Datetime formats also will be cast if received as strings. Strings will have trailing and leading white spaces removed.

__post_init__ may be overridden to include validations required by any use case. In such case, it’s important to include a super call to maintain the aforementioned functionalities.

Returns:None
__weakref__

list of weak references to the object (if defined)

get_db_values() → list[source]

Returns all attributes to save in database with formatted values.

Goes through the fields in the entity and converts them to the expected value to save in the database. For example: datetime values are converted to string with the specific sql format.

Also verifies if a field contains in metadata database=False and excludes it from the list if so. Default for database is True.

Returns:Serialized values to save in database
nova_api.entity.generate_id() → str[source]

Generates an uuid v4.

Returns:Hexadecimal string representation of the uuid.
nova_api.entity.get_time() → datetime.datetime[source]

Get current time without microseconds

Returns:Current datetime with no microseconds.