def from_hash(self, obj): """Convert the hash into the object.""" super(FileKeyValue, self).from_hash(obj) self._set_only_if('file_id', obj, 'file', lambda: Files.get(Files.id == obj['file_id'])) self._set_only_if('key_id', obj, 'key', lambda: Keys.get(Keys.id == obj['key_id'])) self._set_only_if('value_id', obj, 'value', lambda: Values.get(Values.id == obj['value_id']))
def generate_tkvs(json): """Extract TransactionKeyValues as a hash from the json hash.""" keys = [] values = [] tkvs = [] for key, value in pull_kv_by_attr(json): keys.append({'key': key}) values.append({'value': value}) # pylint: disable=protected-access Keys()._set_or_create(keys) Values()._set_or_create(values) # pylint: enable=protected-access for key, value in pull_kv_by_attr(json): # key_obj = Keys.get(key=key) # value_obj = Values.get(value=value) tkvs.append({ 'key': Keys.get(key=key).id, 'transaction': transaction_hash['_id'], 'value': Values.get(value=value).id }) return tkvs
def from_hash(self, obj): """Convert the hash into the object.""" super(TransactionKeyValue, self).from_hash(obj) self._set_only_if( 'transaction_id', obj, 'transaction', lambda: Transactions.get(Transactions.id == obj['transaction_id']) ) self._set_only_if( 'value_id', obj, 'value', lambda: Values.get( Values.id == obj['value_id']) ) self._set_only_if( 'key_id', obj, 'key', lambda: Keys.get(Keys.id == obj['key_id']) )
def generate_fkvs(json): """Extract FileKeyValues as a hash from the json hash.""" file_keys = [] file_values = [] fkvs = [] for key, value, file_id in pull_fkv_by_attr(json): file_keys.append({'key': key}) file_values.append({'value': value}) # pylint: disable=protected-access Keys()._set_or_create(file_keys) Values()._set_or_create(file_values) # pylint: enable=protected-access for key, value, file_id in pull_fkv_by_attr(json): # key_obj = # value_obj = Values.get(value=value) fkvs.append({ 'key': Keys.get(key=key).id, 'value': Values.get(value=value).id, 'file': file_id }) return fkvs
def base_create_dep_objs(cls): """Create all objects that TransactionKeyValue need.""" trans = Transactions() keys = Keys() values = Values() TestTransactions.base_create_dep_objs() trans.from_hash(SAMPLE_TRANSACTION_HASH) trans.save(force_insert=True) TestKeys.base_create_dep_objs() keys.from_hash(SAMPLE_KEY_HASH) keys.save(force_insert=True) TestValues.base_create_dep_objs() values.from_hash(SAMPLE_VALUE_HASH) values.save(force_insert=True)
def base_create_dep_objs(cls): """Create all objects that FileKeyValue need.""" keys = Keys() TestKeys.base_create_dep_objs() keys.from_hash(SAMPLE_KEY_HASH) keys.save(force_insert=True) values = Values() TestValues.base_create_dep_objs() values.from_hash(SAMPLE_VALUE_HASH) values.save(force_insert=True) files = Files() TestFiles.base_create_dep_objs() files.from_hash(SAMPLE_FILE_HASH) files.save(force_insert=True)
def base_create_dep_objs(cls): """Create all objects that InstrumentKeyValue need.""" rel = Relationships() inst = Instruments() keys = Keys() values = Values() TestRelationships.base_create_dep_objs() rel.from_hash(SAMPLE_RELATIONSHIP_HASH) rel.save(force_insert=True) TestInstruments.base_create_dep_objs() inst.from_hash(SAMPLE_INSTRUMENT_HASH) inst.save(force_insert=True) TestKeys.base_create_dep_objs() keys.from_hash(SAMPLE_KEY_HASH) keys.save(force_insert=True) TestValues.base_create_dep_objs() values.from_hash(SAMPLE_VALUE_HASH) values.save(force_insert=True)