Models

Base models for dirty_models.

class dirty_models.models.BaseModel(data=None, flat=False, *args, **kwargs)[source]

Bases: dirty_models.base.BaseData

Base model with dirty feature. It stores original data and saves modifications in other side.

clear()[source]

Clears all the data in the object, keeping original data

clear_all()[source]

Clears all the data in the object

clear_modified_data()[source]

Clears only the modified data

copy()[source]

Creates a copy of model

delete_attr_by_path(field_path)[source]

It deletes fields looked up by field path. Field path is dot-formatted string path: parent_field.child_field.

Parameters:field_path (str) – field path. It allows * as wildcard.
delete_field_value(name)[source]

Mark this field to be deleted

export_data()[source]

Get the results with the modified_data

export_deleted_fields()[source]

Resturns a list with any deleted fields form original data. In tree models, deleted fields on children will be appended.

export_modifications()[source]

Returns model modifications.

export_modified_data()[source]

Get the modified data

export_original_data()[source]

Get the original data

flat_data()[source]

Pass all the data from modified_data to original_data

get_1st_attr_by_path(field_path, **kwargs)[source]

It returns first value looked up by field path. Field path is dot-formatted string path: parent_field.child_field.

Parameters:
  • field_path (str) – field path. It allows * as wildcard.
  • default – Default value if field does not exist. If it is not defined AttributeError exception will be raised.
Returns:

value

get_attrs_by_path(field_path, stop_first=False)[source]

It returns list of values looked up by field path. Field path is dot-formatted string path: parent_field.child_field.

Parameters:
  • field_path (list or None.) – field path. It allows * as wildcard.
  • stop_first (bool) – Stop iteration on first value looked up. Default: False.
Returns:

A list of values or None it was a invalid path.

Return type:

list or None

classmethod get_default_data()[source]

Returns a dictionary with default data.

Returns:dict
get_field_value(name)[source]

Get the field value from the modified data or the original one

get_fields()[source]

Returns used fields of model

get_original_field_value(name)[source]

Returns original field value or None

classmethod get_structure()[source]

Returns a dictionary with model field objects.

Returns:dict
import_data(data)[source]

Set the fields established in data to the instance

import_deleted_fields(data)[source]

Set data fields to deleted

is_modified()[source]

Returns whether model is modified or not

is_modified_field(name)[source]

Returns whether a field is modified or not

reset_attr_by_path(field_path)[source]

It restores original values for fields looked up by field path. Field path is dot-formatted string path: parent_field.child_field.

Parameters:field_path (str) – field path. It allows * as wildcard.
reset_field_value(name)[source]

Resets value of a field

set_field_value(name, value)[source]

Set the value to the field modified_data

class dirty_models.models.DynamicModel(*args, **kwargs)[source]

Bases: dirty_models.models.BaseDynamicModel

DynamicModel allow to create model with no structure. Each instance has its own derivated class from DynamicModels.

class dirty_models.models.FastDynamicModel(*args, **kwargs)[source]

Bases: dirty_models.models.BaseDynamicModel

FastDynamicModel allow to create model with no structure.

get_current_structure()[source]

Returns a dictionary with model field objects.

Returns:dict
get_validated_object(field_type, value)[source]

Returns the value validated by the field_type

class dirty_models.models.HashMapModel(*args, **kwargs)[source]

Bases: dirty_models.base.InnerFieldTypeMixin, dirty_models.models.BaseModel

Hash map model with dirty feature. It stores original data and saves modifications in other side.

copy()[source]

Creates a copy of model

get_validated_object(value)[source]

Returns the value validated by the field_type