MambuPy.api.mambustruct

Basic Struct for Mambu Objects.

Classes

MambuStruct([cf_class])

Basic Struct for Mambu Objects with basic connection functionality.

class MambuPy.api.mambustruct.MambuStruct(cf_class=<class 'MambuPy.api.classes.GenericClass'>, **kwargs)[source]

Bases: MambuMapObj

Basic Struct for Mambu Objects with basic connection functionality.

__assign_new_property(new_property, ent_item, default_prop_path)

Assigns the value ent_item to a new property in the obj.

Parameters:
  • new_property (str) – a new property to be assigned in the obj.

  • ent_item (obj) – the value to assign

  • default_prop_path (str) – a / divided string with the path of the property, in case that new_property doesn’t exists originally in the obj

__convert_basic_types_to_str(data, tzdata=None)

Recursively convert the fields on the data given to strings.

Datetime objects are converted to ISO format, adding TZ info if available on tzdata.

Skips every MambuMapObj owned by this entity.

If the object is an iterable one, it goes down to each of its elements and turns its attributes too

The base case is when it’s a MambuMapObj class (this one) so it just ‘serializes’ the attr atribute.

Parameters:
  • data (obj) – an object whose value should be converted to string.

  • tzdata (obj) – mirror of data, holding only the TZ data for datetimes.

__convert_basic_types_to_str_base_cases(data, tzdata)
__convert_from_dict_basic_types_to_str(it_dict, data, tzdata)
__convert_from_dict_to_basic_types(it_dict, data, tzdata, constantFields)
__convert_from_dict_to_basic_types_non_constant_fields(k, data_dict, data, tzdata)
__convert_from_list_basic_types_to_str(it_list, data, tzdata)
__convert_from_list_to_basic_types(it_list, data, tzdata, constantFields)
__convert_to_basic_types(data, tzdata=None, constantFields=None)

Recursively convert the fields on the data given to a python object.

If data is iterable, iterates its elements and try to convert them.

If data is a string, tries to convert its value to a basic data type:

Basic data types supported:
  • int: an int number

  • float: a floating point number

  • datetime: if the string holds a valid datetime in a date_format

    specific format

A list of fields that should stay as-they-come (strings) is supported. All fields whose name ends with “Key” is also ignored.

Parameters:
  • data (obj) – an object whose value should be converted to a basic type

  • tzdata (obj) – mirror of data, holding only the TZ data for datetimes.

  • constantFields (list) – fields that will be ignored for conversion

__convert_to_basic_types_base_cases(data)
__extract_customfields_from_dict(val_dict, attr, attrs)
__extract_customfields_from_list(val_list, attr, attrs)
__extract_vos_from_list(vo_data, vos_module, voclass, elem, get_entities=False, debug=False)

Extracts the VOs from a list.

Given a list of data representing a VO, extract and instantiate each of them.

Parameters:
  • vo_data (list) – list of VOs to extract

  • vos_module (module) – VOs module from MambuPy

  • voclass (class) – class of the VOs to instantiate

  • elem (obj) – elem at attrs where the list comes from

  • get_entities (bool) – should MambuPy automatically instantiate other MambuPy entities found inside the Value Objects?

  • debug (bool) – print debugging info

Returns:

(vo_obj, already) (tuple)

(vo obj, bool) a list of instances of VOs

and if it has already been instantiated (bool)

__get_enc_key(proprty)

Gets a property from the obj, supposedly holding an encodedKey to return.

Parameters:

proprty (str) – a property to get, supposedly an encodedKey.

Returns:

encodedKey (str) or None

__get_value_or_ek(obj)
__getattribute__(name)[source]

Object-like get attribute for MambuStructs.

If the attribute is not present at the _attrs dict, tries to build a function that calls getEntities(), which in turns will try to instantiate an entity according to the requested attribute name

__getattribute_for_cf(ent, entity)
__getattribute_for_loop(ent, value, mcf)
__getattribute_for_one_cf(ent, value, mcf)
__instance_entity_obj(encoded_key, ent_mod, ent_class, **kwargs)

Instantiates a single MambuPy object calling its get method. If the object doesn’t supports detailsLevel (MambuProduct),

omit it.

Parameters:
  • encoded_key (str) – encoded key of the entity to retrieve from Mambu

  • ent_mod (obj) – module holding the class to instantiate

  • ent_class (str) – class to instantiate

  • kwargs (dict) – extra parameters for the get method

Returns:

MambuPyObject (obj) – instantiation of the object from Mambu

__module__ = 'MambuPy.api.mambustruct'
__update_customfields_from_dict(val_dict, attr, cfs)
__update_customfields_from_list(val_list, attr, cfs)
__update_vos_from_list(vo_obj, vos_module, voclass)

Updates the VOs from a list.

Given a list of VOs, updates each element’s data to the attrs dict.

Parameters:
  • vo_obj (obj) – the VO which data will be updated at the attrs dict.

  • vos_module (module) – VOs module from MambuPy

  • voclass (class) – class of the VOs to instantiate

Returns:

(vo_data, already) (tuple)

(dict, bool) a list of updated data and

if it has already been updated (bool)

_assignEntObjs(entities=None, detailsLevel='BASIC', get_entities=False, debug=False)[source]

Loops entities list of tuples to instantiate MambuPy entities from Mambu.

End result: new properties will appear on the MambuPy object other MambuPy.api.entities.MambuEntity objects retrieved from Mambu

Parameters:
  • entities (list) – list of tuples with information of the entity and property to instantiate. Look at MambuPy.api.mambustruct.MambuStruct._entities

  • detailsLevel (str) – “BASIC” or “FULL” for the retrieved entities

  • get_entities (bool) – should MambuPy automatically instantiate other MambuPy entities found inside the retrieved entities?

  • debug (bool) – print debugging info

_attrs = {}

Properties of the Mambu object

_convertDict2Attrs(*args, **kwargs)[source]

Each element on the attrs attribute gets converted to a proper python object, depending on type.

Some default constantFields are left as is (strings), because they are better treated as strings. This includes any field whose name ends with ‘Key’.

_entities = []

List of Entities in the struct’s _attrs.

Each element must be a 3-tuple:
(“name_of_key_in_attrs”, # element in attrs to obtain the key

“module.class to instantiate”, # class to instantiate for the given key “name_of_obj_in_attrs”) # where in attrs to update with instantiated obj

_extractCustomFields(attrs=None)[source]

Loops through every custom field set and extracts custom field values on the root of the attrs argument.

Parameters:

attrs (dict) – dictionary of fields from where customfields will be extracted. If None, self._attrs will be used

_extractVOs(get_entities=False, debug=False)[source]

Loops _vos list to instantiate the corresponding Value Objects.

If the element in _attrs happens to be a list, the result will be a list of instantiated Value Objects.

End result, the key with the name of the element will be replaced with the instantiated Value Object. And the original element will change its key name from ‘elem’ to ‘vo_elem’.

Parameters:
  • get_entities (bool) – should MambuPy automatically instantiate other MambuPy entities found inside the Value Objects?

  • debug (bool) – print debugging info

_serializeFields(*args, **kwargs)[source]

Every attribute of the Mambu object is turned in to a string representation.

Parameters:
  • data (obj) – an object whose value should be converted to string.

  • tzdata (obj) – mirror of data, holding only the TZ data for datetimes.

_tzattrs = {}

TimeZones info:

_convertDict2Attrs loses TZ info on datetime fields.

We will save them on _tzattrs field. Prefering this method since this allows comparison with datetimes on your code without needing TZ initialized.

For example:

>>> today = datetime.now()
>>> loan.creationDate < today

That code works since now() doesn’t have any TZ info.

If creationDate has TZ info in it, you could not make the comparison.

So, we need to preserve the TZ info somewhere else.

Since TZ info is NOT the same for ALL the Mambu instance (each datetime may have different TZs due to daylight saving time differences for example), _tzattrs will hold the TZ for each datetime field.

Only-date fields are also included but they lack TZ info by definition, so those fileds get a None TZ info.

_updateCustomFields()[source]

Loops through every custom field set and update custom field values with the corresponding property at the root of the _attrs dict, then deletes the property at root

_updateVOs()[source]

Loops _vos list to update the corresponding data in _attrs

End result, the element with the original element in _attr will have its data updated, the Value Object will dissappear and the key name of the original element will return to be from ‘vo_elem’ to ‘elem’

_vos = []

List of Value Objects in the struct’s _attrs.

Each element must be a 2-tuple:

(“name_in_attrs”, “vos.class to instantiate”)

_extractVOs loops this list to instantiate the corresponding Value Objects inside _attrs. If the element in _attrs happens to be a list, the result will be a list of instantiated Value Objects

_updateVOs loops this list to update the corresponding data in _attrs

getEntities(entities, config_entities=None, detailsLevel='BASIC', get_entities=False, debug=False)[source]

Retrieve certain entities from the properties of this MambuEntity.

Parameters:
  • entities (list) – list of strings with the name of the entity to retrieve

  • config_entities (list of tuples) –

    list of tuples with information

    of the entity and property to instantiate

    MambuPy.api.mambustruct.MambuStruct._entities

  • detailsLevel (str) – “BASIC” or “FULL” for the retrieved entities

  • get_entities (bool) – should MambuPy automatically instantiate other MambuPy entities found inside the retrieved entities?

  • debug (bool) – print debugging info

Returns:

MambuPyObject (obj) – instantiation of the object from Mambu