spinetoolbox.spine_db_editor.mvcmodels.parameter_mixins

Miscelaneous mixins for parameter models

authors
  1. Marin (KTH)

date

4.10.2019

Module Contents

Classes

ConvertToDBMixin

Base class for all mixins that convert model items (name-based) into database items (id-based).

FillInAlternativeIdMixin

Fills in alternative names.

FillInParameterNameMixin

Fills in parameter names.

FillInValueListIdMixin

Fills in value list ids.

MakeParameterTagMixin

Makes parameter_tag items.

FillInEntityClassIdMixin

Fills in entity_class ids.

FillInEntityIdsMixin

Fills in entity ids.

FillInParameterDefinitionIdsMixin

Fills in parameter_definition ids.

InferEntityClassIdMixin

Infers entity class ids.

ImposeEntityClassIdMixin

Imposes entity class ids.

ValidateValueInListMixin

Validates that the chosen value is in the value list if one set.

ValidateValueInListForInsertMixin

Validates that the chosen value is in the value list if one set.

ValidateValueInListForUpdateMixin

Validates that the chosen value is in the value list if one set.

MakeRelationshipOnTheFlyMixin

Makes relationships on the fly.

Functions

_parse_csv_list(csv_list)

spinetoolbox.spine_db_editor.mvcmodels.parameter_mixins._parse_csv_list(csv_list)[source]
class spinetoolbox.spine_db_editor.mvcmodels.parameter_mixins.ConvertToDBMixin[source]

Base class for all mixins that convert model items (name-based) into database items (id-based).

build_lookup_dictionary(self, db_map_data)[source]

Begins an operation to convert items.

_convert_to_db(self, item, db_map)[source]

Returns a db item (id-based) from the given model item (name-based).

Parameters
  • item (dict) – the model item

  • db_map (DiffDatabaseMapping) – the database where the resulting item belongs

Returns

the db item list: error log

Return type

dict

class spinetoolbox.spine_db_editor.mvcmodels.parameter_mixins.FillInAlternativeIdMixin(*args, **kwargs)[source]

Bases: ConvertToDBMixin

Fills in alternative names.

Initializes lookup dicts.

build_lookup_dictionary(self, db_map_data)[source]

Builds a name lookup dictionary for the given data.

Parameters

db_map_data (dict) – lists of model items keyed by DiffDatabaseMapping

_convert_to_db(self, item, db_map)[source]

Returns a db item (id-based) from the given model item (name-based).

Parameters
  • item (dict) – the model item

  • db_map (DiffDatabaseMapping) – the database where the resulting item belongs

Returns

the db item list: error log

Return type

dict

class spinetoolbox.spine_db_editor.mvcmodels.parameter_mixins.FillInParameterNameMixin[source]

Bases: ConvertToDBMixin

Fills in parameter names.

_convert_to_db(self, item, db_map)[source]

Returns a db item (id-based) from the given model item (name-based).

Parameters
  • item (dict) – the model item

  • db_map (DiffDatabaseMapping) – the database where the resulting item belongs

Returns

the db item list: error log

Return type

dict

class spinetoolbox.spine_db_editor.mvcmodels.parameter_mixins.FillInValueListIdMixin(*args, **kwargs)[source]

Bases: ConvertToDBMixin

Fills in value list ids.

Initializes lookup dicts.

build_lookup_dictionary(self, db_map_data)[source]

Builds a name lookup dictionary for the given data.

Parameters

db_map_data (dict) – lists of model items keyed by DiffDatabaseMapping

_convert_to_db(self, item, db_map)[source]

Returns a db item (id-based) from the given model item (name-based).

Parameters
  • item (dict) – the model item

  • db_map (DiffDatabaseMapping) – the database where the resulting item belongs

Returns

the db item list: error log

Return type

dict

_fill_in_value_list_id(self, item, db_map)[source]

Fills in the value list id in the given db item.

Parameters
  • item (dict) – the db item

  • db_map (DiffDatabaseMapping) – the database where the given item belongs

Returns

error log

Return type

list

class spinetoolbox.spine_db_editor.mvcmodels.parameter_mixins.MakeParameterTagMixin(*args, **kwargs)[source]

Bases: ConvertToDBMixin

Makes parameter_tag items.

Initializes lookup dicts.

build_lookup_dictionary(self, db_map_data)[source]

Builds a name lookup dictionary for the given data.

Parameters

db_map_data (dict) – lists of model items keyed by DiffDatabaseMapping

_make_parameter_definition_tag(self, item, db_map)[source]

Returns a db parameter_definition tag item (id-based) from the given model parameter_definition item (name-based).

Parameters
  • item (dict) – the model parameter_definition item

  • db_map (DiffDatabaseMapping) – the database where the resulting item belongs

Returns

the db parameter_definition tag item list: error log

Return type

dict

class spinetoolbox.spine_db_editor.mvcmodels.parameter_mixins.FillInEntityClassIdMixin(*args, **kwargs)[source]

Bases: ConvertToDBMixin

Fills in entity_class ids.

Initializes lookup dicts.

build_lookup_dictionary(self, db_map_data)[source]

Builds a name lookup dictionary for the given data.

Parameters

db_map_data (dict) – lists of model items keyed by DiffDatabaseMapping

_fill_in_entity_class_id(self, item, db_map)[source]

Fills in the entity_class id in the given db item.

Parameters
  • item (dict) – the db item

  • db_map (DiffDatabaseMapping) – the database where the given item belongs

Returns

error log

Return type

list

_convert_to_db(self, item, db_map)[source]

Returns a db item (id-based) from the given model item (name-based).

Parameters
  • item (dict) – the model item

  • db_map (DiffDatabaseMapping) – the database where the resulting item belongs

Returns

the db item list: error log

Return type

dict

class spinetoolbox.spine_db_editor.mvcmodels.parameter_mixins.FillInEntityIdsMixin(*args, **kwargs)[source]

Bases: ConvertToDBMixin

Fills in entity ids.

Initializes lookup dicts.

_add_entities_on_the_fly = False[source]
build_lookup_dictionary(self, db_map_data)[source]

Builds a name lookup dictionary for the given data.

Parameters

db_map_data (dict) – lists of model items keyed by DiffDatabaseMapping

_fill_in_entity_ids(self, item, db_map)[source]

Fills in all possible entity ids keyed by entity_class id in the given db item (as there can be more than one entity for the same name).

Parameters
  • item (dict) – the db item

  • db_map (DiffDatabaseMapping) – the database where the given item belongs

Returns

error log

Return type

list

_convert_to_db(self, item, db_map)[source]

Returns a db item (id-based) from the given model item (name-based).

Parameters
  • item (dict) – the model item

  • db_map (DiffDatabaseMapping) – the database where the resulting item belongs

Returns

the db item list: error log

Return type

dict

class spinetoolbox.spine_db_editor.mvcmodels.parameter_mixins.FillInParameterDefinitionIdsMixin(*args, **kwargs)[source]

Bases: ConvertToDBMixin

Fills in parameter_definition ids.

Initializes lookup dicts.

build_lookup_dictionary(self, db_map_data)[source]

Builds a name lookup dictionary for the given data.

Parameters

db_map_data (dict) – lists of model items keyed by DiffDatabaseMapping

_fill_in_parameter_ids(self, item, db_map)[source]

Fills in all possible parameter_definition ids keyed by entity_class id in the given db item (as there can be more than one parameter_definition for the same name).

Parameters
  • item (dict) – the db item

  • db_map (DiffDatabaseMapping) – the database where the given item belongs

Returns

error log

Return type

list

_convert_to_db(self, item, db_map)[source]

Returns a db item (id-based) from the given model item (name-based).

Parameters
  • item (dict) – the model item

  • db_map (DiffDatabaseMapping) – the database where the resulting item belongs

Returns

the db item list: error log

Return type

dict

class spinetoolbox.spine_db_editor.mvcmodels.parameter_mixins.InferEntityClassIdMixin[source]

Bases: ConvertToDBMixin

Infers entity class ids.

_convert_to_db(self, item, db_map)[source]

Returns a db item (id-based) from the given model item (name-based).

Parameters
  • item (dict) – the model item

  • db_map (DiffDatabaseMapping) – the database where the resulting item belongs

Returns

the db item list: error log

Return type

dict

_infer_and_fill_in_entity_class_id(self, item, db_map)[source]

Fills the entity_class id in the given db item, by intersecting entity ids and parameter ids. Then picks the correct entity id and parameter_definition id. Also sets the inferred entity_class name in the model.

Parameters
  • item (dict) – the db item

  • db_map (DiffDatabaseMapping) – the database where the given item belongs

Returns

error log

Return type

list

class spinetoolbox.spine_db_editor.mvcmodels.parameter_mixins.ImposeEntityClassIdMixin[source]

Bases: ConvertToDBMixin

Imposes entity class ids.

_convert_to_db(self, item, db_map)[source]

Returns a db item (id-based) from the given model item (name-based).

Parameters
  • item (dict) – the model item

  • db_map (DiffDatabaseMapping) – the database where the resulting item belongs

Returns

the db item list: error log

Return type

dict

_impose_entity_class_id(self, item, db_map)[source]

Imposes the entity_class id from the model, to pick the correct entity id and parameter_definition id.

Parameters
  • item (dict) – the db item

  • db_map (DiffDatabaseMapping) – the database where the given item belongs

Returns

error log

Return type

list

class spinetoolbox.spine_db_editor.mvcmodels.parameter_mixins.ValidateValueInListMixin[source]

Bases: ConvertToDBMixin

Validates that the chosen value is in the value list if one set.

_convert_to_db(self, item, db_map)[source]

Returns a db item (id-based) from the given model item (name-based).

Parameters
  • item (dict) – the model item

  • db_map (DiffDatabaseMapping) – the database where the resulting item belongs

Returns

the db item list: error log

Return type

dict

abstract _get_parameter_definition_id(self, db_map, item)[source]
class spinetoolbox.spine_db_editor.mvcmodels.parameter_mixins.ValidateValueInListForInsertMixin[source]

Bases: ValidateValueInListMixin

Validates that the chosen value is in the value list if one set.

_get_parameter_definition_id(self, db_map, item)[source]
class spinetoolbox.spine_db_editor.mvcmodels.parameter_mixins.ValidateValueInListForUpdateMixin[source]

Bases: ValidateValueInListMixin

Validates that the chosen value is in the value list if one set.

_get_parameter_definition_id(self, db_map, item)[source]
class spinetoolbox.spine_db_editor.mvcmodels.parameter_mixins.MakeRelationshipOnTheFlyMixin(*args, **kwargs)[source]

Makes relationships on the fly.

Initializes lookup dicts.

static _make_unique_relationship_id(item)[source]

Returns a unique name-based identifier for db relationships.

build_lookup_dictionaries(self, db_map_data)[source]

Builds a name lookup dictionary for the given data.

Parameters

db_map_data (dict) – lists of model items keyed by DiffDatabaseMapping.

_make_relationship_on_the_fly(self, item, db_map)[source]

Returns a database relationship item (id-based) from the given model parameter_value item (name-based).

Parameters
  • item (dict) – the model parameter_value item

  • db_map (DiffDatabaseMapping) – the database where the resulting item belongs

Returns

the db relationship item list: error log

Return type

dict